转换为输出0~31的五位二进制数,左侧不够五位补0
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
int n;
void f(int x) {
stack<int> s;
n=0;
while (x>=1) {
s.push(x%2);
x/=2;
}
while (!s.empty()) {
n=n*10+s.top();
s.pop();
}
printf ("%05d\n",n);
return;
}
int main()
{
for (int i=0;i<32;i++) f(i);
return 0;
}