标签:ret 异或 can pre efi for i++ assert count
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<assert.h>
int hammingDistance(int x, int y) {
int b = x ^ y;//首先二者异或去求不同的位数
int count = 0;
int i = 0;
for (i = 0; i < 32; i++)//要点是32位字节循环
{
if (((b >> i) & 1 )== 1)//按位右移一位与1与去确定不同的位数
count++;
}
return count;
}
int main()
{
int x = 0, y = 0;
scanf("%d%d", &x, &y);
int ret = hammingDistance(x, y);
printf("%d", ret);
}
标签:ret 异或 can pre efi for i++ assert count
原文地址:https://blog.51cto.com/14736509/2489955