strconv
包有FormatInt
,它接受int64
并允许您指定基数.
n := int64(123)
fmt.Println(strconv.FormatInt(n, 2)) // 1111011
DEMO: http://play.golang.org/p/leGVAELMhv
http://golang.org/pkg/strconv/#FormatInt
func FormatInt(i int64, base int) string
个FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.