The APIs that provide byte-swapping routines are listed below. For most situations it’s best to use the routines that match the framework you’re programming in. The Core Foundation and Foundation APIs have functions for swapping floating-point values, while the other APIs listed do not.
POSIX (Portable Operating System Interface) byte ordering functions (ntohl, htonl, ntohs, and htons) are documented in Mac OS X Man Pages.
Darwin byte ordering functions and macros are defined in the header file libkern/OSByteOrder.h. Even though this header is in the kernel framework, it is acceptable to use it from high-level applications.
Core Foundation byte-order functions are defined in the header file CoreFoundation/CFByteOrder.h and described in the Byte-Order Utilities Reference. For details on using these functions, see the Byte Swapping article in Memory Management Programming Guide for Core Foundation.
Foundation byte-order functions are defined in the header file Foundation/NSByteOrder.h and described in Foundation Framework Reference.
The Core Endian API is defined in the header file CarbonCore/Endian.h and described in Core Endian Reference.
Note: When you use byte-swapping routines, the compiler optimizes your code so that the routines are executed only if they are needed for the architecture on which your code is running.
Last updated: 2007-02-26