题目摘要
计算一个32位无符号整数的汉明距离
解法
1. n = n & (n - 1); count++
2. count= count+ (n & 1); n = n>>>1;
注意
1. >>>无符号位右移(补零),>>右移
可问问题
原题
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.