-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
74 lines (59 loc) · 1.25 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package radix_test
import (
"fmt"
"log"
"github.com/bergusman/radix-go"
)
func Example() {
out, err := radix.Convert([]int{1, 3, 3, 7}, 10, 16)
if err != nil {
log.Fatal(err)
}
str, err := radix.Encode(out, "0123456789ABCDEF")
if err != nil {
log.Fatal(err)
}
fmt.Println(str)
// Output: 539
}
func Example_emoji() {
out, err := radix.Convert([]int{1, 3, 3, 7}, 10, 5)
if err != nil {
log.Fatal(err)
}
str, err := radix.Encode(out, "🌑🌘🌗🌖🌕")
if err != nil {
log.Fatal(err)
}
fmt.Println(str)
// Output: 🌗🌑🌖🌗🌗
}
func Example_bitcoin() {
addr := []byte{138, 238, 64, 184, 232, 126, 176, 91, 195, 185, 255, 144, 35, 73, 187, 45, 209, 154, 94, 144}
str, err := radix.Base58Encode(addr, radix.AlphabetBitcoin)
if err != nil {
log.Fatal(err)
}
fmt.Println(str)
// Output: 2wG9ewuHafzR4yG2hYu8U3YmpZxb
}
func ExampleConvert() {
out, err := radix.Convert([]int{1, 3, 3, 7}, 10, 2)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)
// Output: [1 0 1 0 0 1 1 1 0 0 1]
}
func ExampleEncode() {
out, err := radix.Convert([]int{1, 3, 3, 7}, 10, 2)
if err != nil {
log.Fatal(err)
}
str, err := radix.Encode(out, "01")
if err != nil {
log.Fatal(err)
}
fmt.Println(str)
// Output: 10100111001
}