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
+8.7k Golang : Combine slices but preserve order example
+30.9k Golang : Interpolating or substituting variables in string examples
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+8.3k Golang : Check if integer is power of four example
+37.5k Golang : Converting a negative number to positive number
+9.3k Golang : How to get username from email address
+10.1k Golang : How to get quoted string into another string?
+5k Golang : Display packages names during compilation
+6.5k Grep : How to grep for strings inside binary data
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example