For a given number, calculate the number of the corresponding binary 1. For example, 9, the number of the corresponding binary is 1001, then the number of corresponding 1 is 2.
Interview review, more than a month, from the Netease Open Class "Programming Paradigm", and then slightly flip the "premier c ++", then read Yan Weimin's data structure, to be honest, not very good. I can't see the last few chapters. I just switched to introduction to algorithms and wrote 20 blogs about data structures and algorithms. Every morning, I insisted on reading the blog on csdn and learned a lot. Next, I plan to take a look at the beauty of programming and practice what I learned. I will read it around March, and I will look at the interview book before the formal recruitment. I have prepared it. As the foundation is very weak, it is still very difficult to continue to fuel.
Back to the truth, this question seems to be an interesting one, both of which are the beauty of programming and the interview book.
For example, data x, as long as the constant x & (x-1) knows that x is 0.
Code:
# Include <iostream> using namespace std; int func (int x) {int count = 0; while (x) {count ++; x = x & (x-1 );} return count;} int main () {cout <func (99); return 0 ;}