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

猜你喜欢

转载自www.cnblogs.com/leaves1024/p/8985261.html