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 string example?
What is c++ hiding?
What is a block in c++?
Why do we use using namespace std in c++?
Which is better turbo c++ or dev c++?
Which is best ide for c++?
What is lazy initialization in c++?
What is the use of map in c++?
What is do..while loops structure?
What is binary search in c++?
What is the difference between a type-specific template friend class and a general template friend class?
Comment on assignment operator in c++.
Is c better than c++?
Evaluate !(1&&1||1&&0) a) Error b) False c) True
What is abstraction in c++?