Endianness

As a University research lab, we often have students who are not familiar with concepts that the professional security community finds second nature.

Something that I have to explain to new students very often is the concept of Endianness. A concept that reverse engineers and low-level programmers deal with on a daily basis, some students cannot even begin to grasp.

Because of this, we often have to come up with different ways to explain complex concepts to different students. Here’s some of what we’ve come up with for Endianness. Hopefully, this material will be useful to students trying to understand Endianness and teachers trying to explain Endianness and other concepts.

History

We find that some students don’t accept concepts until they understand how they came to be. For these students, we point them to the section on the Wikipedia page that talks about Jonathan Swift’s Gulliver’s Travels

Reasoning

Some students are fine with the concept, but are interested in why they came to be. For these students we provide the following analogy:

Big endian is to English as Little endian is to Hebrew

After explaining that while these languages are written and read in different directions, they are still both languages capable of expressing the same ideas. The creators of these languages may have had their own reasons for picking left or right (which we don’t care about at this juncture), but they both accomplish the same thing. The word size in this analogy is one line of text. See more about word size below.

Visualization

Some students need to see it, instead of just hearing it be explained. This is fairly common and we often use the images on Wikipedia for demonstration:

Little Endian GraphicBig Endian Graphic

These images explain how the same numeric value is stored differently in memory based on which endianness is being used. Recently, I found another insightful graphic in the Intel manuals:

Little Endian

This image gives a different take on little endian, showing how different values would read out of this contiguous segment of memory.

Single Case

Some students will appear to understand the concept when discussing 4-byte values, but then when switching to 2-byte values it’s clear they really don’t understand the whole concept.

Word size is an important concept to make sure students understand when explaining Endianness. Depending on the size of data you’re working with, data will be written into and read out of memory differently. Students need to understand that architectures have a default data size, and the processor will use that size when reading and writing data in big or little endian.

This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Endianness

  1. Alexander Shopov says:

    Do you leave your History-interested students wondering at Swift’s Gulliver? Don’t you talk about the history of processor architectures, need for backward compatibility, etc?

    • Julian Cohen says:

      Yes. As stated in the article, the reasons behind picking an endian isn’t relevant during an introduction.

      No, we don’t talk about architecture history or backwards compatibility because they aren’t related to endianness.

  2. Alexander Shopov says:

    Hmm, I have always thought that picking little-endian architectures helped with compatibility with old software once you move from one architecture to another (for example the 8bit -> 16bit -> 32bit transition in x8x series)
    On the other hand if you are mostly pointing out that endianness does not make one or the other more capable – the tiviality of egg breaking may be the proper metaphor. I am not sure whether this actually answers the question “how they came to be”.
    Still on the third limb for me personally it was revealing to follow the change from one endianness to another in a language – Greek was first written right to left and only after the change from one writing medium to another did it change direction after a period of boustrophedonness.
    Let me not miss the last limb – on the last limb – both the visualization pictures were nice. Especially for those that have the 4byte -> 2byte values. I have been one of them.

Leave a Reply