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 / vadivelt

Hi Small Bug is there in my previous post.
That is corrected in the code written below.

#include<stdio.h>
#include<conio.h>

main()
{
int count = 0, n, i, Res = 0;
int a, b;
printf("GIVE 2 INPUT NO IS\n");
scanf("%d %d", &a, &b);
n = sizeof(int) * 8;
for(i = 0; i<n; i++)
{
Res = ((a >> i & 0x01) ^ (b >> i & 0x01)) ? 1 : 0;
if(Res == 1)
count++;
}
printf("BIT(S) DIFFERENCE: %d", count);
getch();
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are binary trees?

616


Can a file other than a .h file be included with #include?

690


Explain void pointer?

596


What is typedf?

674


How important is structure in life?

597






What is the c value paradox and how is it explained?

585


What is the difference between malloc calloc and realloc in c?

655


Write a program to know whether the input number is an armstrong number.

675


Compare and contrast compilers from interpreters.

692


What is the scope of local variable in c?

584


What is a null pointer in c?

604


List some of the dynamic data structures in C?

794


Define macros.

791


"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

664


Is main an identifier in c?

607