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

I have a varargs function which accepts a float parameter?

1045


Is c still used?

1047


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

1376


Explain how can I manipulate strings of multibyte characters?

1206


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3956


Write a program which returns the first non repetitive character in the string?

1124


What does calloc stand for?

1157


Explain what is wrong in this statement?

1123


How can I copy just a portion of a string?

1308


difference between object file and executable file

6723


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

1065


What is the difference between %d and %i?

1096


Why c language is called c?

1013


Write a program to swap two numbers without using third variable in c?

1130


Is there any data type in c with variable size?

1099