compute the Hamming distance of two integers (considered as binary values, that is, as sequences of bits)
int hamming_distance(unsigned int a, unsigned int b) {
int val = a ^ b;
int dist = 0;
while(val != 0) {
val = val & (val-1);
dist++;
}
return dist;
}