Standard library / encoding/hex

encoding/hex.NewEncoder()

Wraps a writer; each input byte is written as two hex digits without a final padding step. Expected stdout: '476f\n'.

Formal Syntax & Structure

go syntaxgo
func NewEncoder(w io.Writer) io.Writer

Parameters & Attributes

NameTypeDescription
wio.WriterOutput stream.

Return Value

io.Writer

Writer wrapping the output.

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/hex"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var out bytes.Buffer  _, e := hex.NewEncoder(&out).Write([]byte("Go"))  must(e)  fmt.Println(out.String())}
Go Reference