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

what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

680


Can a void pointer point to a function?

574


what are the facialities provided by you after the selection of the student.

1661


Why do we use c for the speed of light?

606


code for replace tabs with equivalent number of blanks

1642






What is the best way to store flag values in a program?

581


Explain what are its uses in c programming?

598


Explain modulus operator.

597


An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above

708


How to compare array with pointer in c?

625


What are the advantages and disadvantages of a heap?

715


When should I declare a function?

623


What are the different types of errors?

647


What are the advantages of using new operator as compared to the function malloc ()?

759


What is static identifier?

705