解法1:
1 int NumberOf1(int n) 2 3 { 4 int count = 0; 5 unsigned int flag = 1; 6 while (flag) 7 { 8 if (n&flag) 9 count++; 10 flag = flag << 1; 11 } 12 }
解法2