public static int convertBase3ToBase10( string value )
{
int fromBase = 3;
string characters = "0123456789";
int maxFromSchemeCharacter = 3;
var fromValue = new StringBuilder( value );
int power = 0;
int result = 0;
while (fromValue.Length > 0)
{
int index = Array.IndexOf( characters.ToCharArray(), fromValue[fromValue.Length - 1] );
// check if character not in numbering scheme
if (index < 0)
throw new FormatException( "Unsupported character in value string" );
// check if character is legal for number base and numbering scheme
if (index >= maxFromSchemeCharacter)
throw new FormatException( "Value contains character not valid for number base" );
result += ( index*(int) Math.Pow( fromBase, power ) );
// overflow check
if (result < 0)
throw new OverflowException();
fromValue.Length--;
power++;
}
return result;
}