The above implementations have the best worst-case behavior of any known algorithm. However, when a value is expected to have few nonzero bits, it may instead be more efficient to use algorithms that count these bits one at a time. As Wegner described in 1960, the bitwise AND of "x" with "x" − 1 differs from "x" only in zeroing out the least significant nonzero bit: subtracting 1 changes the rightmost string of 0s to 1s, and changes the rightmost 1 to a 0. If "x" originally had "n" bits that were 1, then after only "n" iterations of this operation, "x" will be reduced to zero. The following implementation is based on this principle.