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 find out number of on bits in a number?

Answer Posted / vivek

int setbit=1; //Lets start checking from first bit
int numBitSet=0; //Number of bits set in the number

while(setbit>0)
{

if(number&setbit) //bit wise and
numBitSet++;

setbit=setbit<<1;
}

Is This Answer Correct ?    23 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain enumerated types.

1028


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

5338


How can type-insensitive macros be created?

1168


Write a c program to build a heap method using Pointer to function and pointer to structure ?

4678


the 'sizeof' operator reported a larger size than the calculated size for a structure type. What could be the reason?

993


What is typedef?

1407


What is the meaning of 2d in c?

1121


What are pointers in C? Give an example where to illustrate their significance.

1223


What is the sizeof () operator?

1079


What is the right type to use for boolean values in c? Is there a standard type?

1005


How many main () function we can have in a project?

1103


Can an array be an Ivalue?

1089


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

1086


What are linker error?

1088


What is the difference between strcpy() and memcpy() function in c programming?

1082