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 are the implicit member functions of class?
If you don’t declare a return value, what type of return value is assumed?
Is recursion allowed in inline functions?
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
What is friend class in c++ with example?
What is math h in c++?
What is an iterator?
What is a literal in c++?
Explain differences between new() and delete()?
How would perform Pattern Matching in C++?
What is the best book for c++ beginners?
What is near, far and huge pointers? How many bytes are occupied by them?
What is the difference between structures and unions?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
Explain the concept of copy constructor?