public static Primitive Base2Decimal(Primitive number, Primitive Base)
{
try
{
string sNumber = ((string)number).ToLower();
int iBase = (int)Base;
if (iBase < 2 || iBase > 36) return "FAILED";
if (iBase == 2 || iBase == 8 || iBase == 16)
{
return System.Convert.ToInt32(sNumber, iBase);
}
else
{
var reversed = sNumber.Reverse();
decimal result = 0;
int pos = 0;
foreach (char c in reversed)
{
result += CharList.IndexOf(c) * (decimal)System.Math.Pow(iBase, pos);
pos++;
}
return result;
}
}
catch (Exception ex)
{
Utilities.OnError(Utilities.GetCurrentMethod(), ex);
return "FAILED";
}
}