Little Endian Vs Big Endian

CPU like Intel, AMD, Apple Silicon, they store number in little-endian.

For example, the word example, have the following hex byte

00000000 65 78 61 6D:70 6C 65 example

This would store differently in little-endian since it store the small part of the number first

Memory AddressBig-Endian (Motorola, PowerPC, Network)Little-Endian (Intel, AMD, Apple M1/M2)
0065 ('e')65 ('e')
0178 ('x')6c ('l')
0261 ('a')70 ('p')
036d ('m')6d ('m')
0470 ('p')61 ('a')
056c ('l')78 ('x')
0665 ('e')65 ('e')
#include <iostream>

int main() {
    unsigned long hexNumber = 0x6578616d706c65;
    char* toChar = (char*) &hexNumber;
    std::cout << toChar << std::endl;
}
elpmaxe

[!note]
We need to use &hexNumber here since 0x6578616d706c65 if we just do (char*) hexNumber that would tell the computer to look at the memory address of a very big number, that would generate a core dump.

In here we need to use the memory address of hexNumber and cast that to a string.