{
  "slug": "byte-order",
  "term": "Byte order",
  "aliases": [
    "Endianness"
  ],
  "definition": "Byte order is the convention that assigns significance to the positions of bytes in a multibyte value.",
  "note": "Integers: Big-endian puts the most significant byte first; little-endian puts it last. For an unsigned 16-bit integer, hexadecimal bytes 01 02 mean 258 in big-endian and 513 in little-endian. Width, signedness and field layout must also be specified. [python-struct]\n\nConversion: Reinterpreting the same bytes with a different byte-order descriptor differs from swapping the bytes. Starting from big-endian 01 02, changing both preserves 258 while changing either alone gives 513. NumPy exposes these as a dtype view and byteswap(), respectively. [numpy-byteswap]\n\nArrays: Byte order within each element differs from C/Fortran element traversal. In NPY 1.0, the header-length field is little-endian independently of the payload dtype described by the header. [npy-format]\n\nScalar extraction: For a plain unsigned 16-bit NumPy array, extracting an element returns a native-order scalar without changing the array. The scalar does not retain the source byte order. A simple dtype's byteorder may report = when an explicit order matches the host; inspect the array dtype and raw bytes together. [numpy-byteswap] [numpy-dtype-byteorder]",
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "related": [
    "npy",
    "checksum",
    "file-storage"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-06",
  "citations": [
    {
      "id": "python-struct",
      "title": "Python struct: byte order, size and alignment",
      "url": "https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment",
      "accessed": "2026-11-06"
    },
    {
      "id": "numpy-byteswap",
      "title": "NumPy: byte-swapping and dtype reinterpretation",
      "url": "https://numpy.org/doc/stable/user/byteswapping.html",
      "accessed": "2026-11-06"
    },
    {
      "id": "npy-format",
      "title": "NumPy: NPY format and header fields",
      "url": "https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html",
      "accessed": "2026-11-06"
    },
    {
      "id": "hesela-example",
      "title": "Hesela: reading the same bytes in another order",
      "url": "https://hesela.com/analyses/checksums-identity-and-lost-writes/#byte-order",
      "accessed": "2026-11-06"
    },
    {
      "id": "numpy-dtype-byteorder",
      "title": "NumPy: native and explicit dtype byte order",
      "url": "https://numpy.org/doc/stable/reference/generated/numpy.dtype.byteorder.html",
      "accessed": "2026-11-06"
    }
  ],
  "provenance": [
    "Source-reviewed terminology and exact unsigned 16-bit arithmetic; no device or corruption-rate measurement.",
    "Executable worked example: https://hesela.dev/research/byte-order.mjs; regression controls: https://hesela.dev/research/byte-order.test.mjs.",
    "Native NumPy scalar checks: https://hesela.dev/research/byte-order-native.py; the script reports its library version and host order and checks both explicit byte orders without hardware I/O."
  ]
}
