27 lines
557 B
C++
27 lines
557 B
C++
|
|
#include <bits/stdc++.h>
|
||
|
|
using namespace std;
|
||
|
|
int main() {
|
||
|
|
// cout << 512 + 256 + 128 + 64 + 32 + 8 << endl;
|
||
|
|
|
||
|
|
int n = 100;
|
||
|
|
int cnt = 0;
|
||
|
|
for (int i = 31; i >= 0; i--)
|
||
|
|
if (n >> i & 1) cnt++;
|
||
|
|
cout << cnt << endl;
|
||
|
|
|
||
|
|
int x = 100;
|
||
|
|
cnt = 0;
|
||
|
|
while (x) {
|
||
|
|
x = x & (x - 1);
|
||
|
|
cnt++;
|
||
|
|
}
|
||
|
|
cout << cnt << endl;
|
||
|
|
|
||
|
|
// 判断一个数字是不是2的整数次方
|
||
|
|
int n = 100;
|
||
|
|
if (n & (n - 1))
|
||
|
|
cout << "NO" << endl;
|
||
|
|
else
|
||
|
|
cout << "YES" << endl;
|
||
|
|
return 0;
|
||
|
|
}
|