Checking Endianness

Practice memory manipulation by writing code to automatically detect the endianness.

Introduction

Recall that code that exploits a particular endianness format is not compatible with code written for systems with a different endianness format.

Therefore, to make our code portable, we may want to detect the endianness of a system and support both formats.

That said, we need to know how we can detect the endianness format of the current system.

Memory layout

Let’s consider the integer in hexadecimal format 0xAABBCCDD. Let’s see how the CPU stores it in memory in both formats.

Get hands-on with 1200+ tech skills courses.