Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / hex, base64 encoding

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:10:35Z

Updated

2019-03-26T10:10:35Z

package main

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

func main() {
	d := []byte{0x01, 0xff, 0x3a, 0xcd}
	s := hex.EncodeToString(d)
	fmt.Printf("Hex: %s\n", s)

	d2, err := hex.DecodeString(s)
	if err != nil {
		log.Fatalf("hex.DecodeString() failed with '%s'\n", err)
	}
	if !bytes.Equal(d, d2) {
		log.Fatalf("decoded version is different than original")
	}
}
INFO