Decode in Go

Posted by GoDoc
Public (Editable by Users)

Decode decodes src into DecodedLen(len(src)) bytes, returning the actual number of bytes written to dst.

Go
Edit
package main

import (
	"encoding/hex"
	"fmt"
	"log"
)

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

	dst := make([]byte, hex.DecodedLen(len(src)))
	n, err := hex.Decode(dst, src)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", dst[:n])
}