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
+14.1k Javascript : Prompt confirmation before exit
+31.1k Golang : Calculate percentage change of two values
+15.8k Golang : Get digits from integer before and after given position example
+9.5k Mac OSX : Get a process/daemon status information
+25.7k Golang : How to write CSV data to file
+4.8k Facebook : How to place save to Facebook button on your website
+14.8k Golang : Find commonalities in two slices or arrays example
+17.6k Convert JSON to CSV in Golang
+7k Golang : constant 20013 overflows byte error message
+6.8k Golang : Join lines with certain suffix symbol example
+9.6k Golang : Quadratic example