AlgoMaster Logo

Number of 1 Bits

n=11
0 / 11
n0000101176543210count = 0
algomaster.io
Step:n = 11 (00001011). Count the 1-bits: n & (n-1) clears the lowest set bit, so loop until n = 0