获得一个int数中二进制位为1 的个数
int NumberOfOne(int n){
int count = 0;
unsigned int flag = 1;
while (flag){
if (n & flag){
count++;
}
flag = flag << 1;
}
return count;
}
int NumberOfOne2(int n){
int count = 0;
while (n )
{
count++;
n = n &(n - 1);
}
return count;
}