Converts ternary number to decimal.