using System.Text;
namespace FirstProject
{
class Program
{
public static void Main(string[] args)
{
Console.WriteLine(ConvertDecimalToBase(189, 2));
Console.WriteLine(ConvertDecimalToBase(189, 8));
Console.WriteLine(ConvertDecimalToBase(189, 16));
}
public static string ConvertDecimalToBase(int number, int radix)
{
StringBuilder result = new StringBuilder();
while (number / radix != 0)
{
if (number % radix < 10)
{
result.Insert(0, number % radix);
;
}
else
{
result.Insert(0, Char.ConvertFromUtf32(number % radix + 55));
}
number /= radix;
}
_ = number % radix < 10
? result.Insert(0, number % radix)
: result.Insert(0, Char.ConvertFromUtf32(number % radix + 55));
return result.ToString();
}
}
}
[C#] 十进制转其它进制
最新推荐文章于 2024-12-08 16:36:14 发布