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

You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

1770


What is %g in c?

608


What are the 5 types of inheritance in c ++?

571


What are header files? What are their uses?

630


Explain spaghetti programming?

678






Define the scope of static variables.

596


explain how do you use macro?

660


What is anagram in c?

510


What are header files and explain what are its uses in c programming?

602


What is the explanation for cyclic nature of data types in c?

640


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3171


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

1615


What is null character in c?

683


Is that possible to add pointers to each other?

888


What is selection sort in c?

597