Last active
March 11, 2016 13:59
-
-
Save taka-wang/542cb5489d97967dfcad to your computer and use it in GitHub Desktop.
Hex bytes to string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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