private void RunBaseNum() { BaseNumber number = new BaseNumber("19ae", 15); Console.WriteLine(number.ToString()); number = new BaseNumber("19ah", 18); Console.WriteLine(number.ToString()); number = new BaseNumber(7, 5); Console.WriteLine(number.ToString()); var sum = new BaseNumber("42135", 5) + new BaseNumber("42135", 5); Console.WriteLine(sum.ToString()); var differ = new BaseNumber("42135", 5) - new BaseNumber("25451", 5); Console.WriteLine(differ.ToString()); var quotient = new BaseNumber("42135", 5) / new BaseNumber("25451", 5); Console.WriteLine(quotient.ToString()); var remainder = new BaseNumber("42135", 5) % new BaseNumber("25451", 5); Console.WriteLine(remainder.ToString()); Console.WriteLine(new BaseNumber("3", 5) > new BaseNumber("12", 5)); }
public string Convert(string s, int srcBase, int destBase) { BaseNumber n = new BaseNumber(s, srcBase); BaseNumber destBaseNum = new BaseNumber(destBase, srcBase); Stack <string> stack = new Stack <string>(); var zero = new BaseNumber(0, srcBase); while (n > zero) { stack.Push((n % destBaseNum).ToString()); n = n / destBaseNum; } return(string.Join("", stack)); }