Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包
package main
import (
"encoding/hex"
"fmt"
)
func main() {
str := "ff68b4ff"
b, _ := hex.DecodeString(str)
encodedStr := hex.EncodeToString(b)
fmt.Printf("@@@@--bytes-->%02x \n",b)
fmt.Printf("@@@@--string-->%s \n",encodedStr)
}
@@@@--string-->ff68b4ff
@@@@--bytes-->ff68b4ff
原文:https://www.cnblogs.com/Kingram/p/12615667.html