刚开始学 Go
现在有 s = "4e722e3137"的字符串。
我想把 s 转成 []byte{0x4e, 0x72, 0x2e, 0x31, 0x37} 这样的形式,也就是[78 114 46 49 55],也就是字符串里的每两个字符表示成 1 个字节。	
但直接[]byte("4e722e3137")出来的是[52 101 55 50 50 101 51 49 51 55]。
我现在用这样的方法能勉强达到要求:
baseData = []byte("4e722e3137")
var res []byte
for i:=0; i<=len(baseData); i=i+2 {
    raw := string(baseData[i:i+2])
    i, _ := strconv.ParseInt(raw, 16, 8)
    res = append(res, byte(i))
}
但感觉这样确实很蠢,而且性能也不佳,我想问一下有没有更好的方法能转成我需要的格式
|      1xj577      2018-12-28 14:37:55 +08:00 hex.DecodeString("4e722e3137") | 
|      2GeruzoniAnsasu      2018-12-28 14:38:01 +08:00 | 
|  |      3anying      2018-12-28 14:38:06 +08:00 data, err := hex.DecodeString("4e722e3137") | 
|  |      4coyove      2018-12-28 14:39:02 +08:00 以 go 的设计理念来说你的写法没什么不对的,记得检查一下 ParseInt 返回的 err | 
|  |      5maichael      2018-12-28 14:44:39 +08:00 同上,用 hex.DecodeString | 
|      6mzmxcvbn OP 解决了,谢谢楼上的各位 |