计算以二进制表示的整数有多少位1
2019-02-28 本文已影响0人
sakura_1
int CountBits (int n)
{
int count = 0;
while(n > 0)
{
n &= n - 1;
count++ ;
}
return count;
}
int CountBits (int n)
{
int count = 0;
while(n > 0)
{
n &= n - 1;
count++ ;
}
return count;
}