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 / banavathvishnu
int main()
{
int num1,num2;
int cnt = 0;
int temp1,temp2;
printf("enter 2 numbers \n");
scanf("%d %d",&num1,&num2);
while((num1!=0)||(num2!=0))
{
temp1= num1 & 0x01;
temp2 = num2 & 0x01;
if((temp1 ^ temp2)==1)
cnt++;
num1 = num1>>1;
num2 = num2>>1;
}
printf("difference is %d",cnt);
getch();
}
Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What are the 5 data types?
Explain the difference between getch() and getche() in c?
How can I sort a linked list?
What is the use of bitwise operator?
What 'lex' does?
Can you write a programmer for FACTORIAL using recursion?
Why do we use static in c?
using only #include
What is function and its example?
What is c token?
Can we assign integer value to char in c?
Is it valid to address one element beyond the end of an array?
What is the difference between exit() and _exit() function in c?
Can we declare variables anywhere in c?
write a program for the normal snake games find in most of the mobiles.