C# 36进制转10进制
代码是Java转过来的,变量名都没有改……有空再整理一下好了。
public long toDecimal(string input, long bs)
{
try
{
long Bigtemp = 0, temp = 1;
int len = input.Length;
for (int i = len - 1; i >= 0; i--)
{
if (i != len - 1)
temp *= bs;
long num = changeDec(input[i]);
Bigtemp += temp * num;
}
return Bigtemp;
}
catch
{
return 0;
}
}
//十进制转换中把字符转换为数
static int changeDec(char ch)
{
int num = 0;
if (ch >= 'A' && ch <= 'Z')
num = ch - 'A' + 10;
else if (ch >= 'a' && ch <= 'z')
num = ch - 'a' + 36;
else
num = ch - '0';
return num;
}
//数字转换为字符
public static char changToNum(int temp)
{
int n = temp;
if (n >= 10 && n <= 35)
return (char)(n - 10 + 'A');
else if (n >= 36 && n <= 61)
return (char)(n - 36 + 'a');
else
return (char)(n + '0');
}
{
try
{
long Bigtemp = 0, temp = 1;
int len = input.Length;
for (int i = len - 1; i >= 0; i--)
{
if (i != len - 1)
temp *= bs;
long num = changeDec(input[i]);
Bigtemp += temp * num;
}
return Bigtemp;
}
catch
{
return 0;
}
}
//十进制转换中把字符转换为数
static int changeDec(char ch)
{
int num = 0;
if (ch >= 'A' && ch <= 'Z')
num = ch - 'A' + 10;
else if (ch >= 'a' && ch <= 'z')
num = ch - 'a' + 36;
else
num = ch - '0';
return num;
}
//数字转换为字符
public static char changToNum(int temp)
{
int n = temp;
if (n >= 10 && n <= 35)
return (char)(n - 10 + 'A');
else if (n >= 36 && n <= 61)
return (char)(n - 36 + 'a');
else
return (char)(n + '0');
}