EncodeToString / DecodeString
s := hex.EncodeToString([]byte{0xDE, 0xAD, 0xBE, 0xEF})
fmt.Println(s) // "deadbeef"
b, _ := hex.DecodeString(s)
fmt.Printf("% x\n", b)
encoding/hexHex encoding: []byte ↔ ASCII hex string.
s := hex.EncodeToString([]byte{0xDE, 0xAD, 0xBE, 0xEF})
fmt.Println(s) // "deadbeef"
b, _ := hex.DecodeString(s)
fmt.Printf("% x\n", b)
Same formatting as 'xxd' or 'hexdump -C'.
fmt.Print(hex.Dump([]byte("Hello, Go!")))
00000000 48 65 6c 6c 6f 2c 20 47 6f 21 |Hello, Go!|
w := hex.NewEncoder(os.Stdout)
w.Write([]byte("hi"))
fmt.Println() // "6869"