Skip to content

Instantly share code, notes, and snippets.

@balos1
Created December 17, 2017 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balos1/e496ed459f98a0305e02ab14507a9169 to your computer and use it in GitHub Desktop.
Save balos1/e496ed459f98a0305e02ab14507a9169 to your computer and use it in GitHub Desktop.
#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