Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011
, so the function should return 3.
做法很简单。将用十进制表示的n使用基数除法转换为二进制即可。基数除法就是用n不断地对2取余,余数就是n的二进制表达式对应位上的数字,倘若求得为1的话,计数增加。