Golang encoding/hex.EncodeToString() function example

package encoding/hex

EncodeToString returns the hexadecimal encoding of src (1st parameter)

Golang encoding/hex.EncodeToString() function usage example

 package main

 import (
 "encoding/hex"
 "fmt"
 )

 func main() {
 src := []byte("abcd")

 str := hex.EncodeToString(src)

 fmt.Printf("Encoded string in hexadecimal %v \n ", str)
 }

Output :

Encoded string in hexadecimal 61626364

Reference :

http://golang.org/pkg/encoding/hex/#EncodeToString

Advertisement