1
2
3
4
5 package strconv
6
7
8 func Uitob64(u uint64, base uint) string {
9 if base < 2 || 36 < base {
10 panic("invalid base " + Uitoa(base))
11 }
12 if u == 0 {
13 return "0"
14 }
15
16
17 var buf [64]byte
18 j := len(buf)
19 b := uint64(base)
20 for u > 0 {
21 j--
22 buf[j] = "0123456789abcdefghijklmnopqrstuvwxyz"[u%b]
23 u /= b
24 }
25
26 return string(buf[j:])
27 }
28
29
30 func Itob64(i int64, base uint) string {
31 if i == 0 {
32 return "0"
33 }
34
35 if i < 0 {
36 return "-" + Uitob64(-uint64(i), base)
37 }
38 return Uitob64(uint64(i), base)
39 }
40
41
42 func Itoa64(i int64) string { return Itob64(i, 10) }
43
44
45 func Uitoa64(i uint64) string { return Uitob64(i, 10) }
46
47
48 func Uitob(i uint, base uint) string { return Uitob64(uint64(i), base) }
49
50
51 func Itob(i int, base uint) string { return Itob64(int64(i), base) }
52
53
54 func Itoa(i int) string { return Itob64(int64(i), 10) }
55
56
57 func Uitoa(i uint) string { return Uitob64(uint64(i), 10) }