#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int differ_bit(int a, int b)
{
int count = 0;
int tmp = a ^ b;//通过^后tmp里有多少个1就说明两个二进制数里有多少位不同
while (tmp)
{
tmp = tmp & (tmp - 1);
count++;
}
return count;
}
int main()
{
int a = 0;
int b = 0;
printf("请输入两个数:\n");
scanf("%d%d",&a,&b);
int count = differ_bit(a,b);
printf("不同个数:%d\n",count);
return 0;
}
标签:tmp,count,differ,里面,函数,二进制,int,printf,return
From: https://blog.51cto.com/u_16425777/9051050