Standard library / encoding/binary
encoding/binary.NativeEndian
Host byte order; unsuitable for a portable wire format unless the protocol specifies it. Expected stdout: '258\n'.
Formal Syntax & Structure
go syntaxgo
var NativeEndian nativeEndianWorking Example
Example Snippetgo
package main
import ( "encoding/binary" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { p := make([]byte, 2) binary.NativeEndian.PutUint16(p, 258) fmt.Println(binary.NativeEndian.Uint16(p))}