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
I have a varargs function which accepts a float parameter?
Is c still used?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
Explain how can I manipulate strings of multibyte characters?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
Write a program which returns the first non repetitive character in the string?
What does calloc stand for?
Explain what is wrong in this statement?
How can I copy just a portion of a string?
difference between object file and executable file
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What is the difference between %d and %i?
Why c language is called c?
Write a program to swap two numbers without using third variable in c?
Is there any data type in c with variable size?