qfedu-basic-level/day7/d15.cpp

22 lines
396 B
C++
Raw Permalink Normal View History

2023-06-21 14:30:56 +08:00
#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;
}