/**
* 二进制中1的个数
* @Description
*/
public class Test13 {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int count = 0;
while (n != 0){
count++;
n = (n - 1) & n;
}
return count;
}
public int hammingWeight2(int n) {
int count = 0;
int flag = 1;
while (flag != 0){
if ((n & flag) != 0) count++;
flag = flag << 1;
}
return count;
}
public static void main(String[] args) {
System.out.println(new Test13().hammingWeight2(0));
}
}