|
|
|
@ -26,10 +26,15 @@ unsigned int to_decimal(std::string num, int from_base) {
|
|
|
|
|
std::string from_decimal(unsigned int num, int to_base) {
|
|
|
|
|
std::string return_val;
|
|
|
|
|
int val = 0;
|
|
|
|
|
while (num > 0) {
|
|
|
|
|
val = num % to_base;
|
|
|
|
|
return_val.push_back(possible_chars[val]);
|
|
|
|
|
num /= to_base;
|
|
|
|
|
/* Handle the special case of num being zero: In this case, the result is also zero */
|
|
|
|
|
if (num == 0) {
|
|
|
|
|
return_val = "0";
|
|
|
|
|
} else {
|
|
|
|
|
while (num > 0) {
|
|
|
|
|
val = num % to_base;
|
|
|
|
|
return_val.push_back(possible_chars[val]);
|
|
|
|
|
num /= to_base;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reverse the string, since we started from the right */
|
|
|
|
|