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
Can a program run without main?
What is polymorphism in c++? Explain with an example?
Can we change the basic meaning of an operator in c++?
Why c++ is called oop?
What is a rooted hierarchy?
What is the benefit of learning c++?
Define a conversion constructor?
What is c++ flowchart?
What is setfill c++?
write a program that withdrawals,deposits,balance check,shows mini statement. (using functions,pointers and arrays)
What is code reusability in c++?
Is vector a class in c++?
What is the average salary of a c++ programmer?
Explain stack & heap objects?
Incase of a function declaration, what is extern means?