Standard library / encoding/hex

encoding/hex.Encode()

Writes hexadecimal digits into a destination with at least twice the input length. Expected stdout: '4 476f\n'.

Formal Syntax & Structure

go syntaxgo
func Encode(dst, src []byte) int

Parameters & Attributes

NameTypeDescription
dst[]byteDestination byte slice; append APIs preserve its existing prefix.
src[]byteSource bytes to encode or decode.

Return Value

int

Number of bytes or required size, as described above.

Working Example

Example Snippetgo
package main
import (  "encoding/hex"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() { p := make([]byte, 4); n := hex.Encode(p, []byte("Go")); fmt.Println(n, string(p)) }
Go Reference