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.WriterParameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Output 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())}