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
Why clrscr is used in c?
What is the best style for code layout in c?
Can we declare variable anywhere in c?
Where we use clrscr in c?
What is the mean of function?
FILE PROGRAMMING
Explain what is a stream?
What is clrscr in c?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
Write a code to generate a series where the next element is the sum of last k terms.
What is c language used for?
Explain how can I make sure that my program is the only one accessing a file?
Can the curly brackets { } be used to enclose a single line of code?
What is structure pointer in c?
Why void is used in c?