2,190
社区成员
发帖
与我相关
我的任务
分享
func HexToBytes(hex string) ([]byte) {
length := len(hex) / 2
bytes := make([]byte, length)
rs := []rune(hex)
for i := 0; i < length; i++ {
s := string(rs[i*2 : i*2+2])
value, _ := strconv.ParseInt(s, 16, 10)
bytes[i] = byte(value & 0xFF)
}
return bytes
}
package main
import (
"fmt"
"strconv"
)
func main() {
byarr := []byte("4100010045")
i, _ := strconv.ParseInt(string(byarr), 10, 64)
s := strconv.FormatInt(i, 16)
fmt.Println(s)
}