Go hex.EncodeToString: Encode Byte Slice to Hex String
The 'hex.EncodeToString' function in Go is used to encode a byte slice into its hexadecimal representation as a string. The function takes a byte slice as an argument and returns a string.
Here is an example of how to use 'hex.EncodeToString':
package main
import (
"encoding/hex"
"fmt"
)
func main() {
data := []byte('hello world')
encoded := hex.EncodeToString(data)
fmt.Println(encoded)
}
The output of this program will be:
68656c6c6f20776f726c64
This is the hexadecimal representation of the string 'hello world'.
原文地址: https://www.cveoy.top/t/topic/fWmd 著作权归作者所有。请勿转载和采集!