将int转化为2进制,看含有的1的个数

int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}

假定x = 9999。 答案:8


原文地址:https://www.cnblogs.com/byfei/p/3112402.html