BasePad
Code sample
The convert() method converts a number to the specified base.
Here is the C# version.
I coded it by hand because the .NET library currently offers
only binary, octal or hexadecimal conversions.
private string convert(long num, int newBase)
{
int d;
char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuilder output = new StringBuilder();
while (num > 0)
{
d = (int)(num % newBase);
output.Append(digits[d]);
num /= newBase;
}
return reverse(output.ToString());
}
private string reverse(string str)
{
char[] c = str.ToCharArray();
Array.Reverse(c);
return new string(c);
}
The Java version, for comparison.
Much easier, and not restricted to running on Windows!
private String convert(long num, int newBase)
{
return Long.toString(num, newBase);
}