Golang encoding/hex.DecodeString() function example
package encoding/hex
DecodeString returns the bytes represented by the hexadecimal string s (1st parameter).
Golang encoding/hex.DecodeString() function usage example
package main
import (
"encoding/hex"
"fmt"
"os"
)
func main() {
str := "abcd"
b, err := hex.DecodeString(str)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Decoded bytes %v \n ", b)
}
Output :
Decoded bytes [171 205]
IF there is an error in decoding the string, it will look like this :
encoding/hex: invalid byte: U+00E4 'ä'
exit status 1
Reference :
Advertisement
Something interesting
Tutorials
+7.4k Golang : Example of custom handler for Gorilla's Path usage.
+33.6k Golang : How to check if slice or array is empty?
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+15.3k nginx: [emerg] unknown directive "ssl"
+32.4k Golang : Math pow(the power of x^y) example
+6k Javascript : Get operating system and browser information
+6.3k Golang : How to search a list of records or data structures
+6.1k Golang : Dealing with backquote
+20.6k Golang : Secure(TLS) connection between server and client
+87.7k Golang : How to convert character to ASCII and back
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+6.7k Golang : Skip or discard items of non-interest when iterating example