/*
* 32位无符号数最大为2147483647
* Java中没有无符号类型,所以此题不能用n%2的方法解题
* 32位无符号数最大为2147483647
* Java中没有无符号类型,所以此题不能用n%2的方法解题
*/
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int bits = 0;
int t = 0;
while(n!=0){
bits += (n&1);
n = n >>> 1;
}
return bits;
}
}