MCPcopy Create free account
hub / github.com/SmartPool/smartpool-client / BigToBase62

Function BigToBase62

types.go:65–89  ·  view source on GitHub ↗

return 11 chars base 62 representation of a big int base chars are 0-9 a-z A-Z

(num *big.Int)

Source from the content-addressed store, hash-verified

63// return 11 chars base 62 representation of a big int
64// base chars are 0-9 a-z A-Z
65func BigToBase62(num *big.Int) string {
66 digits := []byte{}
67 n := big.NewInt(0)
68 n.Add(n, num)
69 zero := big.NewInt(0)
70 base := big.NewInt(62)
71 for {
72 mod := big.NewInt(0)
73 n, mod = n.DivMod(n, base, mod)
74 mBytes := mod.Bytes()
75 if len(mBytes) == 0 {
76 digits = append(digits, 0)
77 } else {
78 digits = append(digits, mod.Bytes()[0])
79 }
80 if n.Cmp(zero) == 0 {
81 break
82 }
83 }
84 l := len(digits)
85 for i := 0; i < 11-l; i++ {
86 digits = append(digits, 0)
87 }
88 return base62DigitsToString(digits)
89}
90
91func (h SPHash) Str() string { return string(h[:]) }
92func (h SPHash) Bytes() []byte { return h[:] }

Callers

nothing calls this directly

Calls 2

base62DigitsToStringFunction · 0.85
BytesMethod · 0.45

Tested by

no test coverage detected