题解 | #求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; }