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
Explain bit masking in c?
Why is c called c?
What is the purpose of main( ) in c language?
What is a macro?
What is the use of getchar functions?
What does it mean when the linker says that _end is undefined?
In c language can we compile a program without main() function?
How many levels deep can include files be nested?
write a program to find out prime number using sieve case?
What is a keyword?
What are the types of pointers in c?
What are the 4 types of programming language?
What is an lvalue?
How is actual parameter different from the formal parameter?
hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm