Detecting the endianness of the platform

Endianness defines the order in which bytes that represent large numerical values are stored in memory.

There are two types of endianness:

Taking care of endianness is especially essential when exchanging data with other systems. If a developer sends a 32-bit integer, say, 0x01020304, as it is, it may be read as 0x04030201 if the endianness of the receiver does not match the endianness of the sender. That is why data should be serialized.

In this recipe, we will learn how to determine the endianness of our target system.