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

void main()
{
unsigned int a, b, c;
int count = 0;

printf("Enter 2 numbers:");
scanf("%d %d", &a, &b);

c = a ^ b; /* "c" holds bits set for different bits
in "a" and "b" *
/
while(c)
{
c &= (c-1);
count++;
}

printf("The different bits set:%d", count);
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is cohesion and coupling in c?

1041


What is a sequential access file?

1187


What is a pointer in c plus plus?

1317


Write a Program to accept different goods with the number, price and date of purchase and display them

6244


What is the difference between text and binary modes?

1200


Explain 'bit masking'?

1096


How do I create a directory? How do I remove a directory (and its contents)?

1177


What are the standard predefined macros?

1152


How can you allocate arrays or structures bigger than 64K?

1157


Can static variables be declared in a header file?

1069


Do you know the difference between malloc() and calloc() function?

1073


What are the types of functions in c?

991


Write a program to print fibonacci series using recursion?

1072


How do you redirect a standard stream?

1118


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

1274