#include <stdio.h>
int main(int argc, char **argv)
{
while(1){
int num, count = 0;
printf("Please input the num:");
scanf("%d", &num);
if(num % 2 != 0 || num == 1)
count ++;
while(num > 1){
num = num >> 1;
if(num % 2 != 0 || num == 1)
count ++;
}
printf("%d\n", count);
}
return 0;
}
位运算 计算一个int整数的二进制形式中有几位是1
最新推荐文章于 2022-12-22 20:05:39 发布