"""
Using bit operator AND(&) to compare the number with 1,
if the last bit of the number is 1 which means we found a 1 bit, then update the count by 1;
if the last bit of the number is 0, no need to update the count;
right shif the number as current last bit has been processed.
"""
class Solution:
def hammingWeight(self, n):
ans = 0
while (n):
ans += n & 1
n >>= 1
return ans