将十进制数字转换为其他进制的扩展方法
static class Util
{
public static int ConvertToBase(this int i, int baseToToConvert)
{
if (baseToToConvert < 2 || baseToToConvert > 10)
{
throw new ArgumentOutOfRangeException("Value cannot be convert to base:" + baseToToConvert.ToString());
}
int result = 0;
int iterations = 0;
do
{
int nextDigit = i % baseToToConvert;
i /= baseToToConvert;
result += nextDigit * (int)Math.Pow(10, iterations);
iterations++;
} while (i != 0);
return result;
}
}