Golang⼗六进制字符串和byte数组互转Golang⼗六进制字符串和byte数组互转
需求
Golang⼗六进制字符串和byte数组互相转换,使⽤"encoding/hex"包
实现Demo
package main
import (
"encoding/hex"
"fmt"
go语言字符串转数组)
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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。