Date: agosto 25, 2025
Author: Guillermo Garcia
Categories: Embedded C programming Tags: Embedded C programming
In this article, we will look at the difference between Little Endian and Big Endian and how this impacts embedded systems.
Table of Contents
The endianness refers to the byte order used by your computer or microcontroller or a machine to read or write a single “machine word” in memory (32-bit machine’s word size is 32-bit and 64-bit machine’s word size is 64-bit ). In other words, The endian will decide how to store multiple bytes in computer memory.
In Little-endian, LSB (Least significant byte) is stored first or to a lower memory address. Intel x86, Pentium are using this Little Endian.
Thus, the little-endian byte order means, when the computer writes a word (Multi Byte) into memory, it begins by writing the Lowest byte to the lowest memory address and continues until it has written the highest byte to the highest memory address. It does this by writing subsequent and ascending memory addresses, no matter the endianness.
In Big Endian, MSB (Most significant byte) is stored first or to a lower memory address. Big-endian is implemented in PowerPC and most networking devices.
The big-endian byte order means, when the computer writes a word (Multi Byte) into memory, it begins by writing the highest byte to the lowest memory address and continues until it has written the lowest byte to the highest memory address.
Consider the number 0x11223344. This number is written with hexadecimal digits (prefix “0x”). Its decimal value is 287454020. It consists of 4 bytes: 0x11, 0x22, 0x33 and 0x44.
In this value LSB is 0x44 and MSB is 0x11.
Now assume that the computer wants to write this number into memory beginning at address 100. This 4-byte value. So it will use the memory address 100, 101, 102, 103.
If the computer uses the Big endian byte order, it begins with the MSB (byte 0x11) and writes it at address 100. Then it writes the next byte 0x22 at address 101, the byte 0x33 at address 102, and at last the MSB (byte 0x44) at the last address 103. This results in the following memory content:
Memory Address 100 101 102 103 Content 0x11 0x22 0x33 0x44
If the computer uses the Little endian byte order, it begins with the LSB (byte 0x44) and writes it at address 100 and then it goes the word backward until it writes the MSB. So it writes the next byte 0x33 at address 101, then it writes 0x22 at address 102, and at last the MSB 0x11 at address 103. Note again that the computer uses sequential ascending addresses, no matter the endianness. This result is the following memory content:
Memory Address 100 101 102 103 Content 0x44 0x33 0x22 0x11
htonl, ntohl, etc. in C) when dealing with network or storage formats.CPU Endianness in Embedded Systems
Deja una respuesta