Big-endian, explained for five-year-olds

Imagine two little boxes

Computers often store a number in two boxes because one box is not big enough.

Suppose the number is written as:

12 34

Big-endian means the computer puts the most important box first:

[big box] [small box]`n   12        34

Little-endian means it puts the small box first:

[small box] [big box]`n   34        12

Neither one is more correct. They are simply two different ways to line up the same two boxes.

Why screens care

A colour pixel can be packed into two bytes using RGB565. The first byte contains part of the colour and the second byte contains the rest.

If the screen expects big-endian but the computer sends little-endian, the screen reads the two bytes backwards. It is like reading a word by looking at the letters in the wrong order. The picture still appears, but the colours can look very strange.

The tiny rule

Before sending a two-byte pixel, ask:

Does this screen want the big box first or the small box first?

For this display, the ESPHome image is configured as RGB565 with big_endian byte order. That tells the firmware to send the two pixel bytes in the order the display expects.

A friendly takeaway

Big-endian is not a scary computer monster. It is just:

Put the biggest part first.

Little-endian is:

Put the littlest part first.

The important thing is that both the sender and the receiver agree.

Leave a Reply

Your email address will not be published. Required fields are marked *