Byte-Order Utilities

Overview

When handling binary data transmitted or shared across platforms, you need be concerned with how each platform stores numerical values. A platform stores values either in big-endian or little-endian format. On big-endian machines, such as PowerPC machines, values are stored with the most-significant bytes first in memory; on little-endian machines, such as Pentium machines, values are stored with the least-significant bytes first. A multibyte value transmitted to a platform with a different format will be misinterpreted if it is not converted properly by one of the computers.

You identify the native format of the current platform using the CFByteOrderGetCurrent function. Use functions such as CFSwapInt32BigToHost and CFConvertFloat32HostToSwapped to convert values between different byte order formats.

Topics

Core Foundation Byte Order Utilities Miscellaneous Functions

CFByteOrderGetCurrent

Returns the byte order of the current computer.

CFConvertDoubleHostToSwapped

Converts a 64-bit double from the host’s native byte order to a platform-independent format.

CFConvertDoubleSwappedToHost

Converts a 64-bit double from a platform-independent format to the host’s native byte order.

CFConvertFloat32HostToSwapped

Converts a 32-bit float from the host’s native byte order to a platform-independent format.

CFConvertFloat32SwappedToHost

Converts a 32-bit float from a platform-independent format to the host’s native byte order.

CFConvertFloat64HostToSwapped

Converts a 64-bit float from the host’s native byte order to a platform-independent format.

CFConvertFloat64SwappedToHost

Converts a 64-bit float from a platform-independent format to the host’s native byte order.

CFConvertFloatHostToSwapped

Converts a 32-bit float from the host’s native byte order to a platform-independent format.

CFConvertFloatSwappedToHost

Converts a 32-bit float from a platform-independent format to the host’s native byte order.

CFSwapInt16

Swaps the bytes of a 16-bit integer.

CFSwapInt16BigToHost

Converts a 16-bit integer from big-endian format to the host’s native byte order.

CFSwapInt16HostToBig

Converts a 16-bit integer from the host’s native byte order to big-endian format.

CFSwapInt16HostToLittle

Converts a 16-bit integer from the host’s native byte order to little-endian format.

CFSwapInt16LittleToHost

Converts a 16-bit integer from little-endian format to the host’s native byte order.

CFSwapInt32

Swaps the bytes of a 32-bit integer.

CFSwapInt32BigToHost

Converts a 32-bit integer from big-endian format to the host’s native byte order.

CFSwapInt32HostToBig

Converts a 32-bit integer from the host’s native byte order to big-endian format.

CFSwapInt32HostToLittle

Converts a 32-bit integer from the host’s native byte order to little-endian format.

CFSwapInt32LittleToHost

Converts a 32-bit integer from little-endian format to the host’s native byte order.

CFSwapInt64

Swaps the bytes of a 64-bit integer.

CFSwapInt64BigToHost

Converts a 64-bit integer from big-endian format to the host’s native byte order.

CFSwapInt64HostToBig

Converts a 64-bit integer from the host’s native byte order to big-endian format.

CFSwapInt64HostToLittle

Converts a 64-bit integer from the host’s native byte order to little-endian format.

CFSwapInt64LittleToHost

Converts a 64-bit integer from little-endian format to the host’s native byte order.

Data Types

CFSwappedFloat32

Structure holding a 32-bit float value in a platform-independent byte order.

CFSwappedFloat64

Structure holding a 64-bit float value in a platform-independent byte order.

Constants

CFByteOrder

Flags that identify byte order.