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
Explain what is the use of a semicolon (;) at the end of every program statement?
#include
Does c have an equivalent to pascals with statement?
A banker has a seif with a cipher. Not to forget the cipher, he wants to write it coded as following: each digit to be replaced with the difference of 9 with the current digit. The banker chose a cipher. Decipher it knowing the cipher starts with a digit different than 9. I need to write a program that takes the cipher from the keyboard and prints the new cipher. I thought of the following: Take the input from the keyboard and put it into a string or an array. Go through the object with a for and for each digit other than the first, substract it from 9 and add it to another variable. Print the new variable. Theoretically I thought of it but I don't know much C. Could you give me any kind of hint, whether I am on the right track or not?
What extern c means?
Calculate 1*2*3*____*n using recursive function??
Explain what is the benefit of using enum to declare a constant?
What is typedef?
Explain what is wrong in this statement?
Can you mix old-style and new-style function syntax?
what are non standard function in c
Lists the benefits of c programming language?
What is a pointer and how it is initialized?
Explain what are its uses in c programming?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none