Explain the difference between big-endian and little-endian byte ordering. Why does this matter when writing portable C++ code?
Last updated
Endianness is the byte order of multi-byte values in memory. Big-endian stores the most significant byte first (network order), little-endian stores the least significant first (x86, ARM).
It breaks portability when raw bytes cross boundaries (files, networks, other hardware), since the same bytes decode to different values.
Pick a fixed serialization order and convert with
htonl/ntohl, C++20std::endian/std::byteswap, or explicit byte shifts instead of dumping struct memory.