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 / subhash
void main()
{
unsigned int a, b, c;
int count = 0;
printf("Enter 2 numbers:");
scanf("%d %d", &a, &b);
c = a ^ b; /* "c" holds bits set for different bits
in "a" and "b" *
/
while(c)
{
c &= (c-1);
count++;
}
printf("The different bits set:%d", count);
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is FIFO?
What does a function declared as pascal do differently?
Can main () be called recursively?
What does c mean in basketball?
Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?
What is scanf_s in c?
What is union in c?
Differentiate fundamental data types and derived data types in C.
Can two or more operators such as and be combined in a single line of program code?
Is flag a keyword in c?
A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference
What is scope and lifetime of a variable in c?
Is linux written in c?
What is the use of #include in c?
Explain setjmp()?