Write a program to display the no of bit difference between
any 2 given numbers
eg: Num1 will 12->1100
Num2 will 7->0111 the difference in bits are 2.
Answer Posted / guest
The Question has to be corrected !!!. According to the
input given in the question, the bits difference should be
3.
#include<stdio.h>
#include<conio.h>
main()
{
int count = 0, n, i, Res = 0;
int a, b;
printf("GIVE 2 INPUT NOS\n");
scanf("%d%d", &a, &b);
n = sizeof(int);
for(i = 0; i<n; i++)
{
Res = ((a >> i & 0x01) & (b >> i & 0x01)) ? 1 : 0;
if(Res == 0)
count++;
}
printf("BIT(S) DIFFERENCE: %d", count);
getch();
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
How many loops are there in c?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
differentiate built-in functions and user – defined functions.
When should we use pointers in a c program?
How can I read a binary data file properly?
Explain void pointer?
What is the hardest programming language?
Why c language is called c?
What is variable and explain rules to declare variable in c?
Explain the use of bit fieild.
Is flag a keyword in c?
Explain what are compound statements?
What is the 'named constructor idiom'?
Describe the modifier in c?
How will you find a duplicate number in a array without negating the nos ?