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
When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
Is c is a high level language?
What is a 'null pointer assignment' error?
What is the difference between struct and typedef struct in c?
What is the purpose of main() function?
What is time null in c?
What is line in c preprocessor?
What is getche() function?
Tell me what is null pointer in c?
What is the use of bit field?
How reliable are floating-point comparisons?
What is the argument of a function in c?
What is the main difference between calloc () and malloc ()?
Write a code to determine the total number of stops an elevator would take to serve N number of people.
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?