#include #include using namespace std; string IntToNum(int number, int base); int StringToInt(string number, int base); char DigitToChar(int digit); int CharToDigit(char c); int main() { int base, number; string otherRep; int convertBack; for (base = 2; base < 22; base += 3) { for(number = 2; number < 20; number ++) { otherRep = IntToNum(number, base); convertBack = StringToInt(otherRep, base); if (convertBack != number) { cout << "Error converting " << number << " to base " << base << " and back!" << endl; } cout << number << " in base " << base << " is " << otherRep << endl; } } return 0; } char DigitToChar(int digit) { char returnValue; if (digit < 10) { returnValue = char('0' + digit); } else if (digit >= 10 and digit <= 36) { returnValue = char ('A' + digit-10); } else { cout << "Error converting " << digit << " to a char " << endl; } return returnValue; } int CharToDigit(char c) { int returnValue = 0; c = toupper(c); if ('0' <= c and c <= '9') { returnValue = c-'0'; } else if ( 'A' <= c and c <= 'Z') { returnValue = 10+c-'A'; } else { cout << "Error coverting '" << c << "' to a digit" << endl; } return returnValue ; } string IntToNum(int number, int base){ string returnValue; int digit; while (number > 0) { digit = number % base; number = number / base; returnValue = DigitToChar(digit) + returnValue; } return returnValue; } int StringToInt(string number, int base){ int returnValue=0; int i; for(i=0;i