Hamming Distance:
For example, two binary number: 1011 and 1000's HD(Hamming distance) is 2.
The 10000 and 01111's HD is 5.
Here is the code:
Can some one explain it to me?
Thanks!
short HammingDist(short x, short y)
{
short dist = 0;
char val = x^y;// what's the meaning?
while(val)
{
++dist;
val &= val - 1; // why?
}
return dist;
}
^
is a bitwise XOR en.wikipedia.org/wiki/Exclusive_or&
is bitwise AND – Neolith