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
What is scanf () in c?
What is the process to create increment and decrement stamen in c?
What are the properties of union in c?
What are the advantages of using new operator as compared to the function malloc ()?
What are identifiers in c?
Differentiate between declaring a variable and defining a variable?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What is the right type to use for boolean values in c?
Is fortran faster than c?
What language is windows 1.0 written?
What are the advantages and disadvantages of pointers?
What is d'n in c?
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.
What does the function toupper() do?
Why do we use null pointer?