Standard library / encoding/binary
encoding/binary.BigEndian
Most significant byte first. Common for network protocols. Expected stdout: '0102\n'.
Formal Syntax & Structure
go syntaxgo
var BigEndian bigEndianWorking 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.BigEndian.PutUint16(p, 258); fmt.Printf("%x\n", p) }