Skip to main content

Integer & Endianness Explorer

Integer0x12345678→ unsigned 32-bit, DCBA

Valueunsigned 32-bit

unsigned
305419896
hex
0x1234_5678
as signed
305419896

Bits · 32bit 31 … bit 0

  1. byte A

  2. byte B

  3. byte C

  4. byte D

Each bit is a button: click it to flip that bit.

Bytes by significancenext

Memorynext

step 2 of 4

305419896 fits in an unsigned 32-bit integer. In hex that's 0x1234_5678.

305419896 fits in an unsigned 32-bit integer. In hex that's 0x1234_5678.

How it works

Type an integer and watch it become bytes in memory. Switch between little-endian and big-endian, high-word-first and low-word-first, 8 to 64 bits, signed or unsigned, and see what the same bytes mean under every order.

How an integer becomes bytes

Memory is addressed one byte at a time, but most integers are wider than a byte. A 32-bit integer takes four consecutive addresses, so every system has to decide which of its four bytes goes at the lowest address. That decision is the byte order, or endianness.

The explorer names the bytes by significance, the way the “ABCD” notation does. A is the most significant byte and the last letter is the least significant, so 0x12345678 is A = 0x12, B = 0x34, C = 0x56 and D = 0x78. Each byte keeps its colour from the bit pattern down to memory, so you can follow it to its address.

Storing a value happens in the same stages every time:

  1. Value. The number has to fit the type: an unsigned 8-bit integer holds 0 to 255, a signed one −128 to 127.
  2. Two’s complement. A negative number is stored as its magnitude with every bit inverted, plus one. That’s why −1 is all ones and every negative value has its top bit set.
  3. Bytes. The bit pattern is cut into bytes. This step is the same on every machine.
  4. Words. For layouts that care about words, the bytes are grouped into 16- or 32-bit words.
  5. Memory. The byte order and word order decide which byte goes at which address.

Little-endian and big-endian

Big-endian stores the most significant byte first: 0x12345678 becomes 12 34 56 78, the order you would write it down. It’s the byte order of TCP/IP headers, which is why it’s also called network byte order, and of many file formats.

Little-endian stores the least significant byte first: 78 56 34 12. x86 processors are little-endian, and so is almost every ARM system in practice. One nice property: the byte at the lowest address is always the low byte, whatever the width, so reading a 32-bit value as 16 or 8 bits from the same address still gives its low part.

Neither order is faster in general. What matters is that the writer and the reader agree. A program that stores 1 little-endian (01 00 00 00) and reads it back big-endian gets 16,777,216. The inspector’s Same bytes, other orders table shows every reading of the current memory.

When word order matters too

Some systems split a wide value into words first and order the words separately from the bytes inside them. That gives two more 32-bit layouts:

PatternByte order in each wordWord orderWhere you meet it
ABCDBigHigh word firstBig-endian, network order
DCBALittleLow word firstLittle-endian, x86
BADCLittleHigh word firstThe PDP-11’s 32-bit values (“middle-endian”)
CDABBigLow word firstMany Modbus devices sending a 32-bit value in two 16-bit registers

Modbus itself only defines 16-bit registers, which it sends big-endian. How a 32-bit value is split across two registers is left to the device, so the same reading can arrive as ABCD from one vendor and CDAB from another. When a value from a device looks absurd, a swapped word order is one of the first things to check.

The word order setting only has an effect when the value is wider than one word. With a 16-bit word, a 32-bit value is two words and a 64-bit value is four.

Try it

  1. Little-endian: 0x12345678

    Before the memory stage, decide which byte of 0x12345678 will sit at the lowest address. Then switch Byte order to Big in Settings and compare.

  2. A negative number: −2

    Step through the two’s complement stage. Why does −2 become 0xFFFE, and which byte holds 0xFE in memory?

  3. Middle-endian (PDP-11)

    Compare this layout with plain little-endian. Which bytes moved, and which stayed next to each other?

  4. Reading with the wrong order

    Open the inspector and read the same four bytes as big-endian. What would a value of 256 turn into?

Each one opens the matching scenario in the explorer above.

Where this comes from

Memory addressing and byte order are introduced in Architecture chapter 5: the memory hierarchy.

The explorer models plain integers in memory. It leaves out bit order within a byte on serial links, alignment and padding, and floating-point layouts, which have their own Floating-Point Explorer.