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 cohesion and coupling in c?
What is a sequential access file?
What is a pointer in c plus plus?
Write a Program to accept different goods with the number, price and date of purchase and display them
What is the difference between text and binary modes?
Explain 'bit masking'?
How do I create a directory? How do I remove a directory (and its contents)?
What are the standard predefined macros?
How can you allocate arrays or structures bigger than 64K?
Can static variables be declared in a header file?
Do you know the difference between malloc() and calloc() function?
What are the types of functions in c?
Write a program to print fibonacci series using recursion?
How do you redirect a standard stream?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above