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

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

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

#include <stdio.h>
//#include <math.h>
int main() {
    int a = 0x00;
    scanf("%d",&a);
    int count1 = 0;
    int temp = 0x00000001;//0x10000000;
    for(int i = 0; i < 32; i++)
    {
        //temp = pow(2,i);
        if(0 != ((temp << i) & a))
            count1++;
    }
    printf("%d",count1);
    return 0;
}

全部评论

相关推荐

09-21 21:14
门头沟学院
否极泰来来来来:和他说:这里不好骂你,我们加个微信聊
点赞 评论 收藏
分享
09-13 18:00
武汉大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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