Golang中的[]byte与16进制(String)之间相互转换

[]byte -> String(16进制)

1 src := []byte("Hello")
2 encodedStr := hex.EncodeToString(src)
3 // 注意"Hello"与"encodedStr"不相等,encodedStr是用字符串来表示16进制

 

String -> []byte

1 test, _ := hex.DecodeString(encodedStr)
2 fmt.Println(bytes.Compare(test, src)) // 0

 

原文:ttps://blog.csdn.net/jason_cuijiahui/article/details/79418557

posted on 2018-05-03 14:44  泣血  阅读(3074)  评论(0编辑  收藏  举报

导航