1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <array>
#include <iostream>
#include <string>
std::string to_hex(unsigned number)
{
static const std::array<char, 16> hexdigits =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',};
std::string hex;
while (number != 0) {
hex.push_back(hexdigits[number % 16]);
number /= 16;
}
return {hex.rbegin(), hex.rend()};
}
int main()
{
unsigned number;
std::cin >> number;
std::cout << to_hex(number) << std::endl;
}
|