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


Please Help Members By Posting Answers For Below Questions

Is this program statement valid? INT = 10.50;

679


What is main () in c?

580


What is the difference between ā€˜gā€™ and ā€œgā€ in C?

2493


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

593


What is the difference between mpi and openmp?

725






How can I list all of the predefined identifiers?

570


What is header file definition?

561


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

634


What's the right way to use errno?

611


Explain what math functions are available for integers? For floating point?

603


What are the functions to open and close the file in c language?

587


Why is %d used in c?

559


What does 3 mean in texting?

604


What is enumerated data type in c?

615


How can I read a binary data file properly?

627