在 bitcount.c 中编写一个名为 bitCount() 的函数,该函数返回其无符号整数参数的二进制表示形式的 1 位数。记得填写识别信息并运行完成的程序来验证正确性。
/*
Name:
Lab section time:
*/
#include <stdio.h>
int bitCount (unsigned int n);
int main ( ) {
printf ("# 1-bits in base 2 representation of %u = %d, should be 0\n",
0, bitCount (0));
printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
1, bitCount (1));
printf ("# 1-bits in base 2 representation of %u = %d, should be 16\n",
2863311530u, bitCount (2863311530u));
printf ("# 1-bits in base 2 representation of %u = %d, should be 1\n",
536870912, bitCount (536870912));
printf ("# 1-bits in base 2 representation of %u = %d, should be 32\n",
4294967295u, bitCount (4294967295u));
return 0;
}
int bitCount (unsigned int n) {
/* your code here */
}
有人可以帮我准确理解那问的是什么吗?bitCount 是否应该将输入的十进制转换为二进制,然后计算 1 的个数?