Hamming distance calculation for 8-bit C binary values

I am writing a new program that compares 2 two-digit unsigned integers. Compares distances. But my algorithm does not work like that. Can you tell me what is wrong with this code :( THANKS A LOT !!

this is my method of counting;

int countHammDist(unsigned int n, unsigned int m)
{
int i=0;
unsigned int count = 0 ;
for(i=0; i<8; i++){
if( n&1 != m&1 ) {
    count++;
    }
n >>= 1;
m >>= 1;

}
return count;
}

a and b are 8 bit binary files.

 PrintInBinary(a);
 PrintInBinary(b);

 printf("\n %d", countHammDist(a,b));

let me show you the conclusion;

Enter two unsigned integers (0-99): 55 64
Your choices are 55 and 64
Number A: 00110111
Number B: 01000000
Hamming distance is ; 5
+4
source share
2 answers

Put the brackets around n & 1 and m & 1.

if ((n&1) != (m&1))

http://ideone.com/F7Kyzg

This is because! = Before &: http://www.swansontec.com/sopc.html

+7
source

m, .

, . ( })

+2

All Articles