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

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

假定x = 9999。 答案:8


posted @ 2012-06-27 19:09  byfei  阅读(170)  评论(0)    收藏  举报