26 lines
483 B
C++
26 lines
483 B
C++
|
|
#include <bits/stdc++.h>
|
||
|
|
using namespace std;
|
||
|
|
|
||
|
|
// 十进制转十六进制
|
||
|
|
string toHex(int x) {
|
||
|
|
string res;
|
||
|
|
while (x) {
|
||
|
|
int t = x % 16;
|
||
|
|
if (t >= 10)
|
||
|
|
res += t - 10 + 'A';
|
||
|
|
else
|
||
|
|
res += t + '0';
|
||
|
|
x /= 16;
|
||
|
|
}
|
||
|
|
reverse(res.begin(), res.end());
|
||
|
|
if (res.empty())
|
||
|
|
return "00";
|
||
|
|
if (res.size() == 1)
|
||
|
|
return "0" + res;
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
int main() {
|
||
|
|
for (int x = 0; x <= 255; x++)
|
||
|
|
cout << toHex(x) << endl;
|
||
|
|
return 0;
|
||
|
|
}
|