Created
December 17, 2017 08:32
-
-
Save balos1/e496ed459f98a0305e02ab14507a9169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
int hammingDistance(int x, int y) { | |
int diff = x^y; | |
int distance = 0; | |
for (int i = 0; i < 32; ++i) { | |
if ((diff & (1 << i)) != 0) { | |
++distance; | |
} | |
} | |
return distance; | |
} | |
int main() { | |
int dist = hammingDistance(0xFE, 0xFF); | |
printf("distance = %d\n", dist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment