1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
# include <iostream>
# include <cmath>
int main (int, char **) {
/* symbol table for place values. */
static char constexpr sym[36] = {
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V',
'W','X','Y','Z'
};
/* Convert this value */
unsigned const N = 12941; // 12941 = 0x328D
/* ...to radix 16. Constraint: 1 < rx <= sizeof(sym) */
uint64_t constexpr rx = 16;
for (int place = floor(log(N) / log(rx)); place >= 0; place--)
std::cout << sym[static_cast<unsigned int>(N / pow(rx, place)) % rx];
std::cout << "\n";
}
|