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

What is scanf () in c?

656


What is the process to create increment and decrement stamen in c?

581


What are the properties of union in c?

582


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

750


What are identifiers in c?

626






Differentiate between declaring a variable and defining a variable?

600


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

659


What is the right type to use for boolean values in c?

576


Is fortran faster than c?

572


What language is windows 1.0 written?

567


What are the advantages and disadvantages of pointers?

570


What is d'n in c?

624


Create a structure to specify data on students as given below: Roll number, Name, Department, Course, and Year of joining. Assume that there are not more than 450 students in the collage. (a) Write a function to print the names of all students who joined in the last 3 years. (b) Write a function to print the data of a student whose roll numbers are divisible by 4.

594


What does the function toupper() do?

645


Why do we use null pointer?

599