#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int m = 0, n = 0, x = 0, y = 0;
int i = 0, count = 0;
printf("请输入m和n:\n");
scanf("%d%d", &m, &n);
for (i = 0; i < 32; i++)
{
x = (m >> i) & 1; //将m的二进制中第i+1位的值赋给x
y = (n >> i) & 1; //将n的二进制中第i+1位的值赋给y
if (x != y) //判断x和y是否相等
count++;
}
printf("m和n有%d个位不同\n", count);
system("pause");
return 0;
}
时间: 2024-10-15 17:25:05