Apr
24
Counting the number of set bits in a number
for( n = 0; b; n++ )
b &= (b - 1);
Clever trick. e2 has a good explanation of how it works.
for( n = 0; b; n++ )
b &= (b - 1);
Clever trick. e2 has a good explanation of how it works.