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

Give a very good method to count the number of ones in a "n"
(e.g. 32) bit number.

Answer Posted / manish kumar

for (c = 0; n; c++)
n &= n - 1;

Result: the value of c.

complexity:o(logn)

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a program run without main?

1219


What is polymorphism in c++? Explain with an example?

1020


Can we change the basic meaning of an operator in c++?

1107


Why c++ is called oop?

1098


What is a rooted hierarchy?

1145


What is the benefit of learning c++?

975


Define a conversion constructor?

1063


What is c++ flowchart?

1378


What is setfill c++?

1143


write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)

2362


What is code reusability in c++?

1234


Is vector a class in c++?

1030


What is the average salary of a c++ programmer?

1004


Explain stack & heap objects?

1024


Incase of a function declaration, what is extern means?

951