encoding/hex

Package hex implements hexadecimal encoding and decoding.

Index

Functions

func DecodeString

1func DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the hexadecimal string s.

DecodeString expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.

1const s = "48656c6c6f20476f7068657221"
2decoded, err := hex.DecodeString(s)
3if err != nil {
4	log.Fatal(err)
5}
6
7fmt.Printf("%s\n", decoded)

Output

Hello Gopher!

func EncodeToString

1func EncodeToString(src []byte) string

EncodeToString returns the hexadecimal encoding of src.

1src := []byte("Hello")
2encodedStr := hex.EncodeToString(src)
3
4fmt.Printf("%s\n", encodedStr)

Output

48656c6c6f

© Matthias Hochgatterer – MastodonGithubRésumé