Counting number of bits: How does this line work ? n=n&(n-1); [duplicate]
Any unsigned integer ‘n’ will have the following last k digits: One followed by (k-1) zeroes: 100…0 Note that k can be 1 in which case there are no zeroes. (n – 1) will end in this format: Zero followed by (k-1) 1’s: 011…1 n & (n-1) will therefore end in ‘k’ zeroes: 100…0 & … Read more