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


Please Help Members By Posting Answers For Below Questions

What are the 5 data types?

603


Explain the difference between getch() and getche() in c?

566


How can I sort a linked list?

636


What is the use of bitwise operator?

693


What 'lex' does?

720






Can you write a programmer for FACTORIAL using recursion?

615


Why do we use static in c?

635


using only #include and #include Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

1315


What is function and its example?

629


What is c token?

611


Can we assign integer value to char in c?

618


Is it valid to address one element beyond the end of an array?

676


What is the difference between exit() and _exit() function in c?

584


Can we declare variables anywhere in c?

581


write a program for the normal snake games find in most of the mobiles.

1787