hi,

I recently wrote this code to calculate the hamming distance between any two binary numbers... The program accepts the numbers in decimals, performs a bitwise XOR operation and returns the HD...

However, it returns the Hamming distance in decimal... that is if after XOR it gets something like 0010... the hamming distance is 1 but the function returns 2 (the decimal conversion of 0010). how do i get it to return the number of 1s instead of the decimal conversion? The code i wrote is given below -

/*This program lets you enter any two decimal integer values... converts them to binary, performs an XOR operation on the binaries, and returns a decimal value for the binary obtained after XOR*/

```
#include<stdio.h>
#include<stdlib.h>
long int hammingdistance(long int,long int);
main()
{
long int dec1, dec2,x;
printf("\nEnter decimal 1\n");
scanf("%d",&dec1);
printf("Enter decimal 2\n");
scanf("%d",&dec2);
x = hammingdistance(dec1,dec2);
printf("hamming distance = %d", x);
}
/*this function calculates bitwise hamming distance for the given integers*/
long int hammingdistance(long int x, long int y)
{
long int dist, hdist;
hdist = x^y;
return (hdist);
}
```