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
+15.5k Golang : Send email and SMTP configuration example
+9.8k Golang : Get UDP client IP address and differentiate clients by port number
+28.3k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?
+7.3k Golang : Oanda bot with Telegram and RSI example
+4.2k Golang : Convert lines of string into list for delete and insert operation
+4.9k Golang : Use NLP to get sentences for each paragraph example
+7.3k Golang : Emulate NumPy way of creating matrix example
+12.6k Golang : Set image canvas or background to transparent
+14.2k Golang : Get timezone offset from date or timestamp
+6.4k Golang : Trim everything onward after a word
+5k Golang : Find change in a combination of coins example
+22.8k Golang : Upload to S3 with official aws-sdk-go package