1. int NumOf1(int x) {
    2. int count = 0;
    3. while (x) {
    4. count++;
    5. x = x & (x - 1);
    6. }
    7. return count;
    8. }