Leetcode 191: number of 1 bits
In this Leetcode question, we are asked to count and return the number of 1s in the bit representation of 32-bit integers.
Essentially, the problem is quite simple to solve, we can look bit by bit by checking
(n & 1) and divide
n by 2, with bitwise op
n >>= 1;.
However, it get slightly more complicated with negative numbers and the 2-complement representation. In the 2 complement…