编程实现: 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同? 输入例子: 1999 2999 输出例子:6

#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;
}


猜你喜欢

转载自blog.csdn.net/zy_20181010/article/details/79902445