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
What is a unnitialised pointer?
What does std :: flush do?
What does it mean to declare a destructor as static?
What is &x in c++?
What is an undefined reference/unresolved external symbol error and how do I fix it?
Define a constructor - what it is and how it might be called (2 methods)?
What is a syntax in c++?
Are iterators pointers?
Explain how the virtual base class is different from the conventional base classes of the opps.
What is the advantage of an external iterator.
How to tokenize a string in c++?
List the special characteristics of constructor.
What is a pointer with example?
What can I safely assume about the initial values of variables which are not explicitly initialized?
What is c++ good for?