代码如下:
int count_er(int a)
{
int count = 0;
while (a)
{
a = a & (a - 1);
count++;
}
return count;
}
int diff_count(int a,int b)
{
int tem = a ^ b;//这里我按位异或了a和b
printf("%d\n", tem);//打印了按位异或后的值,但实际打印的是a的值?
return count_er(tem);
}
int main()
{
int a = 0;
int b = 0;
scanf("%d%%d", &a, &b);
int different = diff_count(a, b);
printf("%d\n", different);
return 0;
}
我输入的值是a=5和b=3;
5的二进制数是0101;
3的二进制数是0011;(省略了前28位0)
按位异或后的值应该是0110,是6的二进制数;
但实际打印的值是 5
请问是哪里出了问题?
感谢回答!