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 / guest

The Question has to be corrected !!!. According to the
input given in the question, the bits difference should be
3.

#include<stdio.h>
#include<conio.h>

main()
{
int count = 0, n, i, Res = 0;
int a, b;
printf("GIVE 2 INPUT NOS\n");
scanf("%d%d", &a, &b);
n = sizeof(int);
for(i = 0; i<n; i++)
{
Res = ((a >> i & 0x01) & (b >> i & 0x01)) ? 1 : 0;
if(Res == 0)
count++;
}
printf("BIT(S) DIFFERENCE: %d", count);
getch();
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

694


write a c program to find the sum of five entered numbers using an array named number

1624


Why structure is used in c?

602


What is clrscr in c?

684


What is the advantage of an array over individual variables?

748






What is the use of void pointer and null pointer in c language?

637


What is the sizeof () a pointer?

557


What is function and its example?

634


GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)

690


How can I open files mentioned on the command line, and parse option flags?

597


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1419


What is meant by gets in c?

613


What is meant by keywords in c?

624


Using which language Test cases are added in .ptu file of RTRT unit testing???

3605


Hai what is the different types of versions and their differences

1495