iOS Developer Library

Developer

CoreFoundation Framework Reference Byte-Order Utilities Reference

Options
Deployment Target:

On This Page
Language:

Byte-Order Utilities Reference

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.

Functions

  • Returns the byte order of the current computer.

    Declaration

    Swift

    func CFByteOrderGetCurrent() -> CFByteOrder

    Objective-C

    CFByteOrder CFByteOrderGetCurrent ( void );

    Return Value

    The byte order of the current computer. See Byte Order Flags for the list of possible return values.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertDoubleHostToSwapped(_ arg: Double) -> CFSwappedFloat64

    Objective-C

    CFSwappedFloat64 CFConvertDoubleHostToSwapped ( double arg );

    Parameters

    arg

    The real value to convert.

    Return Value

    A structure holding the real value in a canonical byte order.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertDoubleSwappedToHost(_ arg: CFSwappedFloat64) -> Double

    Objective-C

    double CFConvertDoubleSwappedToHost ( CFSwappedFloat64 arg );

    Parameters

    arg

    A structure holding the real value to convert.

    Return Value

    The real value in the host’s native format.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloat32HostToSwapped(_ arg: Float32) -> CFSwappedFloat32

    Objective-C

    CFSwappedFloat32 CFConvertFloat32HostToSwapped ( Float32 arg );

    Parameters

    arg

    The real value to convert.

    Return Value

    A structure holding the real value in a canonical byte order.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloat32SwappedToHost(_ arg: CFSwappedFloat32) -> Float32

    Objective-C

    Float32 CFConvertFloat32SwappedToHost ( CFSwappedFloat32 arg );

    Parameters

    arg

    A structure holding the real value to convert.

    Return Value

    The real value in the host’s native format.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloat64HostToSwapped(_ arg: Float64) -> CFSwappedFloat64

    Objective-C

    CFSwappedFloat64 CFConvertFloat64HostToSwapped ( Float64 arg );

    Parameters

    arg

    The real value to convert.

    Return Value

    A structure holding the real value in a canonical byte order.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloat64SwappedToHost(_ arg: CFSwappedFloat64) -> Float64

    Objective-C

    Float64 CFConvertFloat64SwappedToHost ( CFSwappedFloat64 arg );

    Parameters

    arg

    A structure holding the real value to convert.

    Return Value

    The real value in the host’s native format.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloatHostToSwapped(_ arg: Float) -> CFSwappedFloat32

    Objective-C

    CFSwappedFloat32 CFConvertFloatHostToSwapped ( float arg );

    Parameters

    arg

    The real value to convert.

    Return Value

    A structure holding the real value in a canonical byte order.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFConvertFloatSwappedToHost(_ arg: CFSwappedFloat32) -> Float

    Objective-C

    float CFConvertFloatSwappedToHost ( CFSwappedFloat32 arg );

    Parameters

    arg

    A structure holding the real value to convert.

    Return Value

    The real value in the host’s native format.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Swaps the bytes of a 16-bit integer.

    Declaration

    Swift

    func CFSwapInt16(_ arg: UInt16) -> UInt16

    Objective-C

    uint16_t CFSwapInt16 ( uint16_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt16BigToHost(_ arg: UInt16) -> UInt16

    Objective-C

    uint16_t CFSwapInt16BigToHost ( uint16_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt16HostToBig(_ arg: UInt16) -> UInt16

    Objective-C

    uint16_t CFSwapInt16HostToBig ( uint16_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt16HostToLittle(_ arg: UInt16) -> UInt16

    Objective-C

    uint16_t CFSwapInt16HostToLittle ( uint16_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt16LittleToHost(_ arg: UInt16) -> UInt16

    Objective-C

    uint16_t CFSwapInt16LittleToHost ( uint16_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Swaps the bytes of a 32-bit integer.

    Declaration

    Swift

    func CFSwapInt32(_ arg: UInt32) -> UInt32

    Objective-C

    uint32_t CFSwapInt32 ( uint32_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt32BigToHost(_ arg: UInt32) -> UInt32

    Objective-C

    uint32_t CFSwapInt32BigToHost ( uint32_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt32HostToBig(_ arg: UInt32) -> UInt32

    Objective-C

    uint32_t CFSwapInt32HostToBig ( uint32_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt32HostToLittle(_ arg: UInt32) -> UInt32

    Objective-C

    uint32_t CFSwapInt32HostToLittle ( uint32_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt32LittleToHost(_ arg: UInt32) -> UInt32

    Objective-C

    uint32_t CFSwapInt32LittleToHost ( uint32_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

  • Swaps the bytes of a 64-bit integer.

    Declaration

    Swift

    func CFSwapInt64(_ arg: UInt64) -> UInt64

    Objective-C

    uint64_t CFSwapInt64 ( uint64_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt64BigToHost(_ arg: UInt64) -> UInt64

    Objective-C

    uint64_t CFSwapInt64BigToHost ( uint64_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt64HostToBig(_ arg: UInt64) -> UInt64

    Objective-C

    uint64_t CFSwapInt64HostToBig ( uint64_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is big-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt64HostToLittle(_ arg: UInt64) -> UInt64

    Objective-C

    uint64_t CFSwapInt64HostToLittle ( uint64_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    func CFSwapInt64LittleToHost(_ arg: UInt64) -> UInt64

    Objective-C

    uint64_t CFSwapInt64LittleToHost ( uint64_t arg );

    Parameters

    arg

    The integer whose bytes should be swapped.

    Return Value

    The integer with its bytes swapped. If the host is little-endian, this function returns arg unchanged.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.

Data Types

Miscellaneous

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

    Declaration

    Swift

    struct CFSwappedFloat32 { var v: UInt32 }

    Objective-C

    struct CFSwappedFloat32 { uint32_t v; }; typedef struct CFSwappedFloat32 CFSwappedFloat32;

    Fields

    v

    A 32-bit float value stored with a platform-independent byte order.

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Swift

    struct CFSwappedFloat64 { var v: UInt64 }

    Objective-C

    struct CFSwappedFloat64 { uint64_t v; }; typedef struct CFSwappedFloat64 CFSwappedFloat64;

    Fields

    v

    A 64-bit float value stored with a platform-independent byte order.

    Availability

    Available in iOS 2.0 and later.

Constants

Miscellaneous

  • Flags that identify byte order.

    Declaration

    Swift

    typealias CFByteOrder = CFIndex

    Objective-C

    enum __CFByteOrder { CFByteOrderUnknown, CFByteOrderLittleEndian, CFByteOrderBigEndian }; typedef enum __CFByteOrder CFByteOrder;

    Constants

    • CFByteOrderUnknown

      CFByteOrderUnknown

      The byte order is unknown.

      Available in iOS 2.0 and later.

    • CFByteOrderLittleEndian

      CFByteOrderLittleEndian

      Multi-byte values are stored with the least-significant bytes stored first. Pentium CPUs are little endian.

      Available in iOS 2.0 and later.

    • CFByteOrderBigEndian

      CFByteOrderBigEndian

      Multi-byte values are stored with the most-significant bytes stored first. PowerPC CPUs are big endian.

      Available in iOS 2.0 and later.

    Import Statement

    import CoreFoundation

    Availability

    Available in iOS 2.0 and later.