#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