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

What is a string example?

1014


What is c++ hiding?

1114


What is a block in c++?

982


Why do we use using namespace std in c++?

1027


Which is better turbo c++ or dev c++?

1006


Which is best ide for c++?

966


What is lazy initialization in c++?

1050


What is the use of map in c++?

1092


What is do..while loops structure?

1084


What is binary search in c++?

976


What is the difference between a type-specific template friend class and a general template friend class?

931


Comment on assignment operator in c++.

1073


Is c better than c++?

1020


Evaluate !(1&&1||1&&0) a) Error b) False c) True

1146


What is abstraction in c++?

1270