Skip to content

Instantly share code, notes, and snippets.

@taka-wang
Last active March 11, 2016 13:59
Show Gist options
  • Save taka-wang/542cb5489d97967dfcad to your computer and use it in GitHub Desktop.
Save taka-wang/542cb5489d97967dfcad to your computer and use it in GitHub Desktop.
Hex bytes to string
package main
import (
"fmt"
"encoding/hex"
"strconv"
)
func main() {
a := []byte{0xFF, 0xFA} // []byte{255, 250}
b := hex.EncodeToString(a) // https://golang.org/pkg/encoding/hex/#EncodeToString
s, _ := strconv.ParseInt(b, 16, 32) // https://golang.org/pkg/strconv/#ParseInt
fmt.Println(b) // fffa
fmt.Println(s) // 65530
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment