/// <summary>
/// 计算20进制/// </summary>
/// <param name="x">参数1</param>
/// <param name="y"></param>
/// <returns>20进制结果</returns>
public static string getRes(string x, string y)
{
//定义1-19
string [] ca = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j" };
char[] a = x.ToCharArray();
char[] b = y.ToCharArray();
//检验格式是否正确
foreach (char ah in a)
{
if (!ca.Contains(ah.ToString()))
{
MessageBox.Show("字符" + x + "格式错误");
break;
}
}
foreach (char ah in b)
{
if (!ca.Contains(ah.ToString()))
{
MessageBox.Show("字符" + y + "格式错误");
break;
}
}
//参数长度 使len2a 大于等于len2b
int len2a = a.Length;
int len2b = b.Length;
if (len2a < len2b)
{
//数组交换
len2a = b.Length;
len2b = a.Length;
a = y.ToCharArray();
b = x.ToCharArray();
}
//结果
string[] res = new string[len2a + 1];
res[len2a] = "0";
//数据长度长的和数据长度短的各对应位数的 数值相加
for (int i = len2a - 1, j = len2b - 1; j >= 0; i--, j--)
{
int m = Array.IndexOf(ca, a[i].ToString()) + Array.IndexOf(ca, b[j].ToString())+Int32.Parse( res[i+1]);
if (m >= 20)
{
res[i + 1] = ca[m - 20];
res[i] = Int32.Parse(ca[1]).ToString();
}
else
{
res[i + 1] = ca[m];
res[i] = "0";
}
}
//数据长度长的多余的位数直接赋值给结果数组
for (int i = len2a - len2b-1; i >= 0;i-- )
{
int m = Array.IndexOf(ca, a[i].ToString()) + Int32.Parse(res[i + 1]);
if (m >= 20)
{
res[i + 1] = ca[m - 20];
res[i] = Int32.Parse(ca[1]).ToString();
}
else
{
res[i + 1] = ca[m];
res[i] = "0";
}
}
string resoult="";
//去掉首位0
if (!res[0].Equals("0"))
{
resoult = res[0];
}
for(int i=1;i<res.Length;i++){
resoult += res[i];
}
return resoult;
}
http://download.youkuaiyun.com/detail/wang_xu_xiang/6821533