#include<stdio.h>
#include<windows.h>
int countBits(int x)
{
int c = 0;
while (x)
{
x &= (x - 1);
c++;
}
return c;
}
int main()
{
int ret = countBits(1999 ^ 2999);
printf("%d\n", ret);
system("pause");
return 0;
}
编程实现: 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同? 输入例子: 1999 2999 输出例子:6
最新推荐文章于 2022-08-18 14:46:05 发布