22 lines
396 B
C++
22 lines
396 B
C++
|
#include <iostream>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int n;
|
||
|
cout << "输入一个正整数: ";
|
||
|
cin >> n;
|
||
|
|
||
|
int isStartShow = 0;
|
||
|
for (int i = 31; i >= 0; i--)
|
||
|
{
|
||
|
if ((n >> i) & 1) // 从最高位开始判断: 如果为 0 则不显示
|
||
|
isStartShow = 1;
|
||
|
if (isStartShow)
|
||
|
cout << ((n >> i) & 1);
|
||
|
}
|
||
|
cout << endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|