Simply use the hex.DecodeString() function:
s := "46447381"
data, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
fmt.Printf("% x", data)
Output:
46 44 73 81
Try it on the Go Playground.
Note:
If you just simply print the byte slice using fmt.Println(data), the printed values will be in decimal format that’s why it won’t match your input string (because it is specified in hexadecimal format).
Output of fmt.Println(data) would be:
[70 68 115 129]
These are the same numbers just in decimal base.