Hamming Distance


Hamming Distance between two integers is the number of bits which are different at same position in both numbers

int hammingDistance(int x, int y) 
{ int a=x^y; int c=0; while(a!=0) { if(a%2!=0) c++; a=a/2; } return c; }

No comments

Theme images by enjoynz. Powered by Blogger.