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 pointers in c?
Disadvantages of C language.
Differentiate Source Codes from Object Codes
Write a program to swap two numbers without using third variable?
how to count no of words,characters,lines in a paragraph.
What does calloc stand for?
What is null in c?
What is getche() function?
formula to convert 2500mmh2o into m3/hr
Write the syntax and purpose of a switch statement in C.
Explain what are global variables and explain how do you declare them?
Why pointers are used in c?
What are the application of c?
Define VARIABLE?
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix