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

Why clrscr is used in c?

951


What is the best style for code layout in c?

1043


Can we declare variable anywhere in c?

918


Where we use clrscr in c?

1088


What is the mean of function?

1062


FILE PROGRAMMING

2175


Explain what is a stream?

1029


What is clrscr in c?

1070


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

974


Write a code to generate a series where the next element is the sum of last k terms.

1167


What is c language used for?

921


Explain how can I make sure that my program is the only one accessing a file?

1161


Can the curly brackets { } be used to enclose a single line of code?

1118


What is structure pointer in c?

984


Why void is used in c?

948