Counting Bits


i&i1 clears the last bit set in i. The number of bits set in i would therefore be, the number of bits set in i&i1 plus the bit that the AND operation cleared. For eg, take i = 3 (11). i1 = 2 (10). 3&2 = 2 (10). The answer would be, the number of bits set in 2(=1), plus 1(from the cleared bit) = 2.
