Hey so I have been asked to get the number of different bits between two integers. I have written the code below which seem to work but only for positive numbers. I would love to know what am I doing wrong.
printf("Enter 2 numbers:\n");
scanf("%d %d", &num1, &num2);
xor_num = num1 ^ num2;
while (xor_num != 0) {
if (xor_num & 1) {
xor_num = xor_num >> 1;
bits_on += 1;
}
else
xor_num = xor_num >> 1;
}
printf("There are %d diffrent bits\n", bits_on);