https://github.com/zhulintao/CodingInterviewChinese2/tree/master/15_NumberOf1InBinary
//这种解法在n是负数是会无限循环
int NumberOf1_Solution1(int n)
{
int count = 0;
while (n)
{
if (n & 1)
count++;
n>>=1;
}
return count;
}
int NumberOf1_Solution1(int n)
{
int count = 0;
unsigned int flag = 1;
while (flag)
{
if (n & flag)
count++;
flag = flag << 1;
}
return count;
}
int NumberOf1_Solution2(int n)
{
int count = 0;
while (n)
{
++count;
n = (n - 1) & n;
}
return count;
}