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
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
write a c program to find the sum of five entered numbers using an array named number
Why structure is used in c?
What is clrscr in c?
What is the advantage of an array over individual variables?
What is the use of void pointer and null pointer in c language?
What is the sizeof () a pointer?
What is function and its example?
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)
How can I open files mentioned on the command line, and parse option flags?
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
What is meant by gets in c?
What is meant by keywords in c?
Using which language Test cases are added in .ptu file of RTRT unit testing???
Hai what is the different types of versions and their differences