Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Binary, Hex and Endianness  ›  Capstone Project

Little Endian — Least Significant Byte First

Little Endian 12 minA little-endian machine stores a multi-byte number with its least significant byte at the lowest memory address, so the bytes appear reversed compared with how the number is written.

Little Endian — Least Significant Byte First

Open a memory dump on almost any laptop or phone, look for the number 0x12345678, and you will find the bytes 78 56 34 12. The number has not been scrambled. Most processors today, including x86 chips and ARM chips in their usual mode, are little endian: they store the little end first.

The rule

Little endian: the little end, the least significant byte, goes first.

The least significant byte is the one worth the least, the rightmost hex pair. Little endian puts it at the lowest address:

0x12345678, little endian:
address:  100  101  102  103
byte:      78   56   34   12

Why would anyone choose this? One reason: the byte at the starting address is always the ones byte, whatever the width. The number 5 stored in 8 bytes begins with 05 at the same address as 5 stored in 4 bytes, and addition starts from the low byte just as you add from the rightmost digit.

The real danger is a mismatch: bytes written in one order and read in the other. Suppose a little-endian program writes the 32-bit number 1 as raw bytes: 01 00 00 00. A reader that assumes big endian sees 0x01000000, which is 16,777,216. Nothing crashes; the number is just silently wrong. This is why file formats and protocols state their byte order, and why programs convert explicitly when they read or write binary data.

The shortcut

Split the number into byte pairs and reverse the pairs, not the digits. To read little-endian bytes back, reverse them again and read as normal.

Reading bytes 34 12 as a 16-bit little-endian numberStep 1 of 4
  1. Take the bytes in address order

    34 then 12.

The trap: reversing digits instead of bytes. Reversing 0x1234 digit by digit gives 0x4321, which is wrong. Reversing by byte pairs gives 34 12, which is right.

Drills

Answer fast — trust the rule.

quick drill

How is 0xA1B2C3D4 laid out in little endian, lowest address first?

quick drill

Four bytes in memory are 01 00 00 00. What 32-bit number do they mean on a little-endian machine?

quick drill

The same bytes 01 00 00 00 are read as a big-endian 32-bit number. What value results?

quick drill

Which kind of data is safe to share between big- and little-endian machines without conversion?

Remember

  • Little endian stores the least significant byte at the lowest address.
  • Reverse byte pairs, never single digits: 0x1234 is stored as 34 12.
  • The trap: mixing orders gives silently wrong numbers, so formats must state their byte order.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainThe file that read back wrong

A program on a little-endian laptop writes the 32-bit number 1 to a file as raw bytes. A tool that assumes big endian reads the file and reports 16,777,216. Explain the bytes in the file, why the tool got that number, and how to avoid the problem.