#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> int main() { int num1 = 1999; int num2 = 2299; int count = 0; int ret = num1^num2; //比特位不同异或后结果为1 while (ret) { ret = ret&(ret - 1); count++; } //将异或后的1输出,即有几个比特位不同 printf("%d", count); system("pause"); return 0; }