Skip to content
uencoder

Endianness

Endianness is the byte ordering of multi-byte values in memory: big-endian stores the most significant byte first, little-endian the least significant byte first.

Purpose

It resolves how multi-byte data is stored and transmitted consistently across CPU architectures.

Mechanism

Big-endian: the most significant byte sits at the lowest address (0x010203 stored as 01 02 03), the convention for network protocols. Little-endian: the least significant byte sits at the lowest address (stored as 03 02 01), used by x86/ARM. UTF-16/32 require a BOM or an explicit endianness declaration.

Use cases

  • Network protocol fields (network byte order is big-endian)
  • Binary file formats (e.g., PNG is big-endian, ELF little-endian)
  • Cross-platform data serialization
  • Embedded and driver development

Examples

  • Input
    0x01020304
    Output
    BE: 01 02 03 04 / LE: 04 03 02 01

    The same value in both byte orders

Common errors

Sending host-order integers without network byte order conversion
Convert explicitly with htonl/ntohl or DataView

Related terms

Related tools

References