生成36进制流水号_C#
程序员文章站
2024-03-17 09:40:46
...
机制间在线转换。
10进制转36进制输出到文本文件,然后可再倒入数据库中使用。
class Program
{
static void Main(string[] args)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("Decimal\tSerialLength\tHexadecimal\r\n");
long val = 1, maxnum = 46655;
for (long i = 1; i <= maxnum; i++)//0011~ZZZ
{
stringBuilder.Append( $"{i}\t3\t{ConvertTo36(i).PadLeft(3,'0')}\r\n");
Console.WriteLine(i);
}
System.IO.File.WriteAllText("./NumPools.text", stringBuilder.ToString());
}
/// <summary>
/// 10進制轉36進制
/// </summary>
/// <param name="i">10進制值</param>
/// <returns>36進制值</returns>
public static string ConvertTo36(long i)
{
string s = "";
long j = 0;
while (i >= 36)
{
j = i % 36;
if (j < 10)
s += j.ToString();
else
s += Convert.ToChar(j + 87);
i = i / 36;
}
if (i < 10)
s += i.ToString();
else
s += Convert.ToChar(i + 87);
Char[] c = s.ToCharArray();
Array.Reverse(c);
return Convert.ToString(new string(c)).ToUpper();
}
}
下一篇: JavaScript 16进制转10进制