...

/

Determine Host Byte Order (Endianness)

Determine Host Byte Order (Endianness)

Determine the host byte order (endianness) of a system.

Statement

Write a program to determine the host byte order (endianness) of any system.

The figure below shows the little-endian and big-endian representations of 0x01234567, where A0-A3 are the byte addresses in increasing order.

g Endian representations of 0x01234567 node_low Little Endian array A0 A1 A2 A3 67 45 23 01 node_low2 Big Endian array2 A0 A1 A2 A3 01 23 45 67

Try it yourself

#include <iostream>
#include <cmath>
using namespace std;
// Using enumerated types for easier printing
enum HostByteOrder {
byte_order_little_endian,
byte_order_big_endian
};
HostByteOrder HostByteOrder() {
// TODO: Write - Your - Code
return byte_order_big_endian;
}

Solution

Here is how we determine the endianness of the system:

  • Put a value (where each byte is unique) in an integer.
...