← All notes

Go encoding/binary: numbers, bytes, and varints

Answer: Package binary implements simple translation between numbers and byte sequences. It also handles encoding and decoding of varints. Numbers are translated by reading and writing fixed-size values. LittleEndian is the little-endian implementation of ByteOrder.

Fixed-size values and byte order

The package implements simple translation between numbers and byte sequences.

Reading and writing fixed-size values is how numbers are translated.

A fixed-size value is a fixed-size arithmetic type, or an array or struct containing only fixed-size values.

LittleEndian is the little-endian implementation of ByteOrder and AppendByteOrder. NativeEndian is the native-endian implementation.

The source comment

The source comment describes simple translation between numbers and byte sequences.

It also covers encoding and decoding of varints.

The varint helpers encode and decode single integer values with a variable-length encoding.

Smaller values require fewer bytes under that encoding.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, encoding/binary package reference; Go, encoding/binary source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, encoding/binary package reference; Go, encoding/binary source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:b6q7d7ce

iinventedlight. 2026. "Go encoding/binary: numbers, bytes, and varints." iinventedlight Library, iil:note:b6q7d7ce, version of 2026-11-23. https://iinventedlight.com/library/notes/go-encoding-binary/. License: CC-BY-4.0.

@misc{iil_note_b6q7d7ce,
  author = {{iinventedlight}},
  title = {{Go encoding/binary: numbers, bytes, and varints}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/go-encoding-binary/},
  note = {Permanent ID iil:note:b6q7d7ce. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-encoding-binary.md.