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

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 ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an arrays?

1071


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

3240


The __________ attribute is used to announce variables based on definitions of columns in a table?

1197


Explain how can I pad a string to a known length?

1189


Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1

4262


Which is best book for data structures in c?

1091


Why do we use null pointer?

1054


How do c compilers work?

1120


What is the purpose of void in c?

1065


What is the correct code to have following output in c using nested for loop?

1076


What is function in c with example?

1143


What is the difference between the local variable and global variable in c?

959


What is scope rule in c?

1059


What is getch () for?

1222


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1854