Determine Host Byte Order (Endianness)
Determine the host byte order (endianness) of a system.
We'll cover the following...
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.
Try it yourself
#include <iostream>#include <cmath>using namespace std;// Using enumerated types for easier printingenum HostByteOrder {byte_order_little_endian,byte_order_big_endian};HostByteOrder HostByteOrder() {// TODO: Write - Your - Codereturn 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.