Intro

In computerarchitecture the order in which bytes are stored in memory is referred to as endianess as in “which end?” is stored first.

This byte ordering has two forms, Little and Big.

Little Endian

This is common in x86 architecture processors, where they store two-byte integers with the least significant byte first, in the lowest memory address available, followed by the most significant.

In this context, least significance means the bytes that’s the smallest in the integer.

Big Endian

This is the opposite of Little Endian, the most significant byte is stored first in the lowest memory address, and the least significant byte is stored in the highest memory address allocated to this integer.

This was a popular order among older architectures such as Motorola’s 68k, but is still used today with network communications and file storage.

Compatibility

It’s important to account for and handle different byte ordering when interpreting data across various systems that interact with one another.

Dealing with Different Data Types

Char Strings vs. Numbers

Character strings are sequences of individual bytes, and each byte in a character string represents a single character, think ASCII.
When accessing a string, you’re often treating each byte or character independently, so the overall byte order of the system doesn’t come into play the same way it does with multi-byte numerical values.

For example, the string “HELLO” in ASCII is represented as:

48 45 4C 4C 4F

Whether it’s a big endian or little endian system, it’d still interpret this string the same way, from the first byte to the last.

Numerical Values

However, for multi-byte numerical values, the order in which the bytes are read and interpreted is critical. If a 4-byte integer is read in the wrong byte order, it will represent a completely different value.

Summary

Info

  • Char strings are sequences of individual characters, and the order of characters matters for human interpretation. Byte order within each character doesn’t matter because each character is typically a single byte and treated individually.
  • Numbers that span multiple bytes have a specific value based on the combination of those bytes, so the order in which those bytes are combined matters a lot. Reading them in the wrong order will yield an incorrect numerical value.

References