Convert between []byte and hexadecimal (String) in Golang

[]byte -> String (hexadecimal)

1 src := [] byte ( " Hello " )
 2 encodedStr := hex.EncodeToString(src)
 3  // Note that "Hello" and "encodedStr" are not equal, encodedStr is a string to represent hexadecimal

 

String -> []byte

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

 

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325216044&siteId=291194637