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
Is this program statement valid? INT = 10.50;
What is main () in c?
What is the difference between āgā and āgā in C?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
What is the difference between mpi and openmp?
How can I list all of the predefined identifiers?
What is header file definition?
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none
What's the right way to use errno?
Explain what math functions are available for integers? For floating point?
What are the functions to open and close the file in c language?
Why is %d used in c?
What does 3 mean in texting?
What is enumerated data type in c?
How can I read a binary data file properly?