您的位置:首页 > 其它

一个整数转化为二进制数后包含1的个数

2012-11-25 21:10 260 查看
int Func(int x)

{

int count=0;

while(x!=0)

{

count++;

x=x&(x-1);

}

return count;

}
int _tmain(int argc, _TCHAR* argv[])

{

int x=9999;

cout<<Func(9999)<<endl;

system("pause");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐