Computing

Big Endian vs. Little Endian With a Real Hex Dump

Endianness is the byte order of multi-byte values. One 32-bit number stored both ways, a hex dump from a real machine, and why network order is big endian.

Endianness is the order in which a multi-byte number’s bytes are stored. Big-endian stores the most significant byte first: 0x12345678 becomes 12 34 56 78. Little-endian stores the least significant byte first: 78 56 34 12. The value is the same; only the byte order in memory or in a file differs.

The same number written both ways

We packed 0x12345678 (305,419,896) into four bytes each way with Python and dumped the files with xxd on an Apple Silicon Mac:

$ python3 -c "import struct; open('le.bin','wb').write(struct.pack('<I', 0x12345678))"
$ python3 -c "import struct; open('be.bin','wb').write(struct.pack('>I', 0x12345678))"
$ xxd le.bin
00000000: 7856 3412                                xV4.
$ xxd be.bin
00000000: 1234 5678                                .4Vx

The right-hand column is the same bytes read as ASCII: 0x78 is “x”, 0x56 “V”, 0x34 “4”, and 0x12 is unprintable, shown as a dot. On the same machine, sys.byteorder printed little, and packing with the native =I format produced 78 56 34 12.

Try itEnter a hex value and a width to see its bytes in each order.
Decimal value
305419896
Read little-endian bytes as if big-endian
0x78563412 (the classic byte-swap bug)
Address+0+1+2+3
Big-endian12345678
Little-endian78563412

Reading little-endian bytes in a dump

The little-endian file again, byte by byte. Select a byte to see what it contributes:

InspectLittle-endian 0x12345678: lowest-value byte at the lowest address
0000

Select a field below or a byte above.

FieldBytesValueMeaning
0–0780x78, the least significant byte (× 1)
1–1560x56 × 256
2–2340x34 × 65,536
3–3120x12 × 16,777,216, the most significant byte

The rule for reading a little-endian value in a hex dump: reverse the bytes, then read them as one hex number. 78 56 34 12 reversed is 12 34 56 78.

Bits are not reversed

Endianness is about the order of bytes. Inside each byte, 0x78 is still 0111 1000; nothing flips the bits. A hex dump of little-endian data shows 78, not 87. (Bit order on a serial wire is a separate topic that hardware handles for you.)

Who uses which

  • Little-endian: x86 and x86-64 processors, and ARM processors as normally configured, including Apple Silicon and most phones. Our test machine reported little.
  • Big-endian: Internet protocol headers (network byte order), many file formats such as PNG and JPEG headers, and some older or embedded processors.
  • Configurable (bi-endian): ARM and several other architectures can run either way, but almost all deployments are little-endian.

Network byte order and htonl

Internet protocols send the most significant byte first, so programs on little-endian machines must swap multi-byte fields before sending and after receiving. The classic C functions are htonl and htons (host to network, long and short) and ntohl and ntohs. On our test machine, Python’s socket.htonl(0x12345678) returned 0x78563412: the bytes were swapped, because host order is little-endian. On a big-endian machine the same call returns its input unchanged.

The Ethernet frame walkthrough shows a big-endian header field in a real frame layout.

The classic bug

Reading little-endian bytes as if they were big-endian gives the byte-swapped number. In Python, int.from_bytes(b'\x78\x56\x34\x12', 'little') is 0x12345678, while 'big' gives 0x78563412 (2,018,915,346), a completely different value. The fix is always to state the byte order explicitly when reading binary data:

  • Python: struct.unpack('<I', data) for little-endian, '>I' or '!I' for big-endian or network order.
  • JavaScript: new DataView(buf).getUint32(0, true) reads little-endian; omit true for big-endian.
  • C/C++: convert with ntohl or, in C++23, std::byteswap when the file’s order differs from the host’s.

To look at the bits inside each byte, convert the hex with the hex to binary converter.

Sources

  1. struct — Interpret bytes as packed binary data — Python documentation. byte order characters <, >, ! and =
  2. RFC 1700: Assigned Numbers (Data Notations) — IETF. Internet protocols transmit the most significant octet first
  3. DataView — MDN. explicit littleEndian argument

How we made this

Measured. We wrote 0x12345678 to two files with Python's struct module (formats '<I' and '>I') and dumped them with xxd; the dumps below are the exact output. sys.byteorder and socket.htonl were run on the same machine.

Performed by Claude, an AI assistant working in the BinConvert repository (Apple Silicon (arm64) Mac, Python 3.14.3, xxd), November 16, 2026.

This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; the hex dumps were re-run and match byte for byte. Review: automated test suite and source check, November 16, 2026.

Spotted an error? Tell us and we will correct it.

Copied to clipboard!