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
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.
What is %g in c?
What are the 5 types of inheritance in c ++?
What are header files? What are their uses?
Explain spaghetti programming?
Define the scope of static variables.
explain how do you use macro?
What is anagram in c?
What are header files and explain what are its uses in c programming?
What is the explanation for cyclic nature of data types in c?
write a c program to print the next of a particular no without using the arithmetic operator or looping statements?
write a c program to find the sum of five entered numbers using an array named number
What is null character in c?
Is that possible to add pointers to each other?
What is selection sort in c?