题解 | #求int型正整数在内存中存储时1的个数#

求int型正整数在内存中存储时1的个数

http://www.nowcoder.com/practice/440f16e490a0404786865e99c6ad91c9

#include<iostream>
#include<bitset>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int op=1;
        int l=sizeof(int)*8;
        int count=0;
        for(int i=1;i<=l;i++)
        {
            if(op&n)
            {
                count++;
            }
            op=op<<1;
        }
        cout<<count<<endl;
    }
    return 0;
}
全部评论

相关推荐

2025-12-16 14:57
门头沟学院 Java
迷茫的大四🐶:是这样的,我都拿到你这同一水平的offer了,那我接你的offer的意义在哪,我一开始想接你们的offer期待是很高的,希望你们下次继续努力
你今年的保底offer是...
点赞 评论 收藏
分享
优秀的大熊猫在okr...:多益:此贼,必有同谋,按律,该当连坐!
你不能接受的企业文化有哪...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务