Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

develop algorithms to add polynomials (i) in one variable

2240


How many types of sorting are there in c?

1114


What do you mean by a sequential access file?

1136


Tell me about low level programming languages.

1190


What is the purpose of void pointer?

1103


How are strings stored in c?

1081


What is the value of c?

1132


If null and 0 are equivalent as null pointer constants, which should I use?

1312


find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

2049


Explain what is the purpose of "extern" keyword in a function declaration?

1127


What are the different categories of functions in c?

1180


in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above

1087


What is function prototype in c language?

1090


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

2044


Explain what is wrong in this statement?

1178