Although both 68K and PowerPC processors were big endian, x86 CPUs access memory in little endian mode. For more information on endian-ness, see [Wikipedia].
Apple have also introduced a page on endian-swapping as part of their [Universal Programming] guidelines.
Both PowerPC and Intel use IEEE floating-point format for 'float' and 'double' types. However, this format does not define an endian-ness - and so, as with integer types, these values are stored the opposite way round in memory.
There are at least four header files available to Carbon applications that provide endian-swapping functions:
Which is used is largely a matter of preference, however CFByteOrder.h does use processor-specific instructions when possible (i.e., when compiling with gcc for either PowerPC or x86).
By convention, "network byte order" (i.e., the byte-order used within structures transmitted over a network) has historically been big-endian. The "host" byte order is either big or little endian depending on the CPU.
POSIX provides four functions for byte-swapping from network to host order, which are often used in Unix/Windows code:
| ntohl | Swap a 32-bit integer from big-endian ("network") to native-endian ("host") |
| ntohs | Swap a 16-bit integer from big-endian ("network") to native-endian ("host") |
| htonl | Swap a 32-bit integer from native-endian ("host") to big-endian ("network") |
| htons | Swap a 16-bit integer from native-endian ("host") to big-endian ("network") |
The "CoreEndian" API was introduced in Mac OS X 10.3, and is defined by Endian.h.
It provides a callback-based approach to endian-swapping data in a given domain, and is used by both the Resource Manager and AppleEvent Manager on Intel systems.