计算X转为二进制后,包含1的数量

来源:互联网 发布:c 调用易语言dll 编辑:程序博客网 时间:2024/05/16 07:02
#include<iostream.h>


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


void main(){
cout <<func(9999);
}
0 0
原创粉丝点击