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
+29.2k Golang : missing Git command
+13k Swift : Convert (cast) Int to String ?
+5.4k Golang : Return multiple values from function
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+6.8k Golang : Join lines with certain suffix symbol example
+7.8k Golang : Lock executable to a specific machine with unique hash of the machine
+21.1k Golang : For loop continue,break and range
+20.2k Golang : Count number of digits from given integer value
+10.5k Generate Random number with math/rand in Go
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+5.3k Javascript : Change page title to get viewer attention
+17.2k Golang : When to use init() function?