The base converter algorithm