#include<stdio.h>
int bitCount(unsigned int b)
{
int count = 0;
while(b)
{
count += b & 0x00000001;
b = b >> 1;
}
return count;
}
void test()
{
unsigned int b;
int ret = 0;
while(scanf("%d", &b) != EOF)
{
ret = bitCount(b);
printf("%d\n", ret);
}
}
int main()
{
test();
return 0;
}
编程之美---求二进制中1的个数
最新推荐文章于 2021-03-16 11:54:00 发布