您的位置:首页 > 职场人生

面试题:求一个INT32整数里面有多少个位是置1 的

2006-09-11 12:20 239 查看
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
int count(int i){
int count=0;
while (i){
++count;
i=(i-1)&i;
}
return count;
}
int main(){
int i;
while (cin>>i){
cout<<count(i)<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐