#include #include using namespace std; string ToBaseN(int value, int base); int FromBaseN(string value, int base); int main() { for (int i = 0; i < 20; ++i) { for (int base = 2; base < 17; ++ base) { string newNum{ToBaseN(i, base)}; cout << base << " " << i << " " << newNum << " " << FromBaseN(newNum, base) << endl; } cout << endl; } return 0; } int DecodeDigit(char digit) { digit = tolower(digit); if (digit <= '9') { return digit - '0'; } else if (digit >= 'a' and digit <= 'z') { return 10 + digit - 'a'; } else { return 0; } } char EncodeDigit(int digit) { if (digit <= 9) { return static_cast(digit + '0'); } else { return static_cast(digit - 10 + 'a'); } } string ToBaseN(int value, int base){ string newBase; int digit; while (value > 0) { digit = value % base; value = value / base; char digitRep = EncodeDigit(digit); newBase = digitRep + newBase; } if (newBase == "") { newBase = "0"; } return newBase; } int FromBaseN(string value, int base){ size_t i; int decimal{0}; for(i = 0; i < value.size(); ++i) { int digit {DecodeDigit(value[i])}; decimal = decimal * base + digit ; } return decimal; }