你的朋友 Eliud 从奶奶 Tigist 那里继承了一座农场。她的奶奶是个发明家,总喜欢把东西造得过分复杂。鸡舍里有一块数字显示屏,上面显示一个经过编码的数字,表示所有可以捡到的鸡蛋的位置。
Eliud 想请你写一个程序,显示鸡舍里鸡蛋的实际数量。
位置信息的编码方式如下:
1,空位置的标记 0。示例 1:
Chicken Coop:
_ _ _ _ _ _ _
|E| |E|E| | |E|
Resulting Binary:
1 0 1 1 0 0 1
Decimal number on the display:
89
Actual eggs in the coop:
4
示例 2:
Chicken Coop:
_ _ _ _ _ _ _ _
| | | |E| | | | |
Resulting Binary:
0 0 0 1 0 0 0 0
Decimal number on the display:
16
Actual eggs in the coop:
1
你的任务是统计一个数字的二进制表示中 1 的个数。
不要使用标准库提供的位计数功能!请改用其他基础工具自己解决。