Standard library / encoding/hex

encoding/hex.DecodeString()

Decodes an even-length hexadecimal string; accepts uppercase and lowercase digits. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
func DecodeString(s string) ([]byte, error)

Parameters & Attributes

NameTypeDescription
sstringInput text or bytes.

Return Value

([]byte, error)

Resulting bytes (possibly partial for decoding) and error.

Working Example

Example Snippetgo
package main
import (  "encoding/hex"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() { p, e := hex.DecodeString("476F"); must(e); fmt.Println(string(p)) }
Go Reference