func Convert(num, fromBase, toBase string) (string, error) {
	if num == "" {
		return "", ErrInvalidNumber
	}
	if len(fromBase) < 2 {
		return "", ErrInvalidFromBase
	}
	if len(toBase) < 2 {
		return "", ErrInvalidToBase
	}
	fromLenRunes := utf8.RuneCountInString(fromBase)
	toLenRunes := utf8.RuneCountInString(toBase)
	numLen := utf8.RuneCountInString(num)
	number, ipos := make([]int, numLen), 0
	for i, r := range num {
		jpos, found := 0, false
		for _, s := range fromBase {
			if r == s {
				number[ipos] = jpos
				found = true
				break
			}
			jpos++
		}
		if !found {
			return "", &InvalidCharacterError{r, ipos, i}
		}
		ipos++
	}
	todigits, idx := make([]rune, toLenRunes), 0
	for _, r := range toBase {
		todigits[idx] = r
		idx++
	}
	var result []rune
	for {
		divide, newlen := 0, 0
		for i := 0; i < numLen; i++ {
			divide = divide*fromLenRunes + number[i]
			if divide >= toLenRunes {
				number[newlen] = divide / toLenRunes
				divide = divide % toLenRunes
				newlen++
			} else if newlen > 0 {
				number[newlen] = 0
				newlen++
			}
		}
		numLen, result = newlen, append(result, todigits[divide])
		if newlen == 0 {
			break
		}
	}
	for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
		result[i], result[j] = result[j], result[i]
	}
	return string(result), nil
}
Convert num from specified base to a different base.
package baseconv
import (
	"fmt"
	"unicode/utf8"
)
type Error string
func (err Error) Error() string {
	return string(err)
}
type InvalidCharacterError struct {
	r      rune
	pos, n int
}
func (err *InvalidCharacterError) Error() string {
	return fmt.Sprintf("invalid character '%c' at position %d (%d)", err.r, err.pos, err.n)
}
const (
	ErrInvalidNumber Error = "invalid number"
	ErrInvalidFromBase Error = "invalid fromBase"
	ErrInvalidToBase Error = "invalid toBase"
)