#include<iostream>
#include<bitset>
using namespace std;
using namespace std;
// 快速法
int count1(unsigned int n) {
int count = 0;
while (n > 0) { // 所有1都换成0跳出循环
n = n & (n - 1); // 1换0
count++;
}
return count;
}
int count0(unsigned int n) {
int count = 0;
while (n+1) { // 所有0都换成1跳出循环
n = n | (n + 1); // 0换1
count++;
}
return count;
}
int main()
{
unsigned int a = 250;
cout << bitset<32>(a) << endl;
cout << count1(a) << endl;
cout << count0(a) << endl;
system("pause");
return 0;
}