public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int res=0;
int test=1;
for(int i=0;i<32;i++){
if((test&n)!=0){
res++;
}
test=test<<1;
}
return res;
}
}
// 这样也行
// public class Solution {
// public int hammingWeight(int n) {
// int res = 0;
// while(n != 0) {
// res += n & 1;
// n >>>= 1;
// }
// return res;
// }
// }