Endian conversions

Back to Portability

Processor manufacturers present us with two major ways of storing a multi-byte integer into memory. Little endians list the bytes from the least significant to the most signifact. The big endians, in contrast, list the bytes from the most signifact to the least significant.

Endian conversions

When data is stored into files using a direct binary representation, the storage order must be chosen as well. Therefore, when loading from or saving to files, we are presented with two practical problems:

  1. Checking which endianness the computer has.
  2. Converting from the endianness used in the file to the endianness used in the computer (or vice versa).

Pastel provides functions for both of these tasks.

Files

Endian conversion

Testing for endian conversions