#include<stdio.h>
int bit_count(unsigned int n)
{
int count;
for(count = 0; n; n=n &(n - 1))
{
count++;
}
return count;
}
int main()
{ int k;
int num;
printf("输入一个数:");
scanf("%d",&num);
k=bit_count(num);
printf("1的个数为%d\n",k);
return 0;
}
原文地址:http://10738432.blog.51cto.com/10728432/1697470