#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的个数
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
面试题中的二叉树根据和寻路径问题
SciPioneer
2020-07-06 02:57:38
有趣的Google面试题 - Harry Potter走矩阵
SciPioneer
2020-07-06 02:57:38
春假扭腰Bloomberg一游
SciPioneer
2020-07-06 02:57:28
2020年Web前端面试题之Vue相关(最全,最详细)
宅男呀
2020-07-04 22:21:45
2020年Web前端面试题之原生JS(最全,最详细)
宅男呀
2020-07-04 22:21:45
2020年Web前端面试题之React相关(最全,最详细)
宅男呀
2020-07-03 09:31:40
[Google]find a,b,c such that a+b+c
MrRoyLee
2020-07-03 02:28:53
lintcode亚马逊
缪斯赤贫
2020-07-01 01:01:26
2020旷视提前批面试
缪斯赤贫
2020-07-01 01:01:26
Interview - network
ulangch
2020-06-25 05:41:26
Interview(XCJ)
Wang_0_
2020-06-23 04:57:12
First Bad Version - Javascript
RockPaperProgrammer
2020-06-22 15:39:07
C++的priority_queue实现最大堆
ustcqi
2020-06-22 02:11:20