Counting the number of 1 bits in the binary representation of a given integer.
- shift the number right by one bit each time, and check whether the right-most bit is 1
- If yes, count++
- if n is not 0, count++
- assign n = n & (n-1), repeat until n is 0
- method 1: theta(n)
- method 2: O(n)