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 are the implicit member functions of class?

1133


If you don’t declare a return value, what type of return value is assumed?

1006


Is recursion allowed in inline functions?

1135


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

1160


What is friend class in c++ with example?

1118


What is math h in c++?

1244


What is an iterator?

1241


What is a literal in c++?

1164


Explain differences between new() and delete()?

1150


How would perform Pattern Matching in C++?

1316


What is the best book for c++ beginners?

1097


What is near, far and huge pointers? How many bytes are occupied by them?

1160


What is the difference between structures and unions?

1117


In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h

1259


Explain the concept of copy constructor?

1108