1 2 3 4 5 6 7 8 9 10 11
|
constexpr char symbol[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'
};
std::string to_base(int n, int base)
{ return n > 0 ? to_base( n / base, base ) + symbol[n % base] : ""; }
std::string to_quarternary(int n) { return to_base(n, 4); }
std::string to_octal(int n) { return to_base(n, 8); }
|