Golang encoding/hex.Encode() function example
package encoding/hex
Encode encodes src(2nd parameter) into EncodedLen(len(src)) bytes of dst (1st parameter). As a convenience, it returns the number of bytes written to dst, but this value is always EncodedLen(len(src)). Encode implements hexadecimal encoding.
Golang encoding/hex.Encode() function usage example
package main
import (
"encoding/hex"
"fmt"
)
func main() {
str := "abcdef"
src := []byte(str)
dst := make([]byte, hex.EncodedLen(len(src)))
num := hex.Encode(dst, src)
fmt.Printf("Number of bytes written : %v \n", num)
}
Output :
Number of bytes written : 12
Reference :
Advertisement
Something interesting
Tutorials
+27.6k PHP : Convert(cast) string to bigInt
+16k Golang : Get sub string example
+8.8k Golang : Accept any number of function arguments with three dots(...)
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+14.3k Golang : Recombine chunked files example
+5.2k Golang : Issue HTTP commands to server and port example
+9.1k Golang : How to capture return values from goroutines?
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+8k Golang : Sort words with first uppercase letter
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+9.2k Golang : Generate Codabar
+28.5k Golang : Change a file last modified date and time