Max 5 API Reference

Byte Ordering
[Miscellaneous]

Utilities for swapping the order of bytes to match the Endianness of the required platform. More...

Collaboration diagram for Byte Ordering:

Defines

#define C74_LITTLE_ENDIAN   1
 A macro that indicates whether or not the current architecture uses Litte-endian byte ordering (such as is used on an i386 processor).
#define C74_BIG_ENDIAN   0
 A macro that indicates whether or not the current architecture uses Big-endian byte ordering (such as is used on a PPC processor).
#define BYTEORDER_SWAPW16(x)   ((short)(((((unsigned short)(x))>>8)&0x00ff)+((((unsigned short)(x))<<8)&0xff00)))
 Switch the byte ordering of a short integer.
#define BYTEORDER_SWAPW32(x)
 Switch the byte ordering of an integer.
#define BYTEORDER_SWAPF32   byteorder_swapf32
 Switch the byte ordering of a float.
#define BYTEORDER_SWAPF64   byteorder_swapf64
 Switch the byte ordering of a double.
#define BYTEORDER_LSBW16(x)   (x)
 Switch the byte ordering of a short integer from the native swapping to Little-endian (Least Significant Byte).
#define BYTEORDER_LSBW32(x)   (x)
 Switch the byte ordering of an integer from the native swapping to Little-endian (Least Significant Byte).
#define BYTEORDER_LSBF32(x)   (x)
 Switch the byte ordering of a float from the native swapping to Little-endian (Least Significant Byte).
#define BYTEORDER_LSBF64(x)   (x)
 Switch the byte ordering of a double from the native swapping to Little-endian (Least Significant Byte).
#define BYTEORDER_MSBW16(x)   BYTEORDER_SWAPW16(x)
 Switch the byte ordering of a short integer from the native swapping to Big-endian (Most Significant Byte).
#define BYTEORDER_MSBW32(x)   BYTEORDER_SWAPW32(x)
 Switch the byte ordering of an integer from the native swapping to Big-endian (Most Significant Byte).
#define BYTEORDER_MSBF32(x)   BYTEORDER_SWAPF32(x)
 Switch the byte ordering of a float from the native swapping to Big-endian (Most Significant Byte).
#define BYTEORDER_MSBF64(x)   BYTEORDER_SWAPF64(x)
 Switch the byte ordering of a double from the native swapping to Big-endian (Most Significant Byte).

Detailed Description

Utilities for swapping the order of bytes to match the Endianness of the required platform.

An introduction to the issue of endianness can be found at http://en.wikipedia.org/wiki/Endianness.

Of particular relevance is that a Macintosh with a PPC processor uses a Big-endian byte ordering, whereas an Intel processor in a Mac or Windows machine will use a Little-endian byte ordering.

These utilities are defined to assist with cases where byte ordering needs to be manipulated for floats or ints. Note that floats are subject to the same byte ordering rules as integers. While the IEEE defines the bits, the machine still defines how the bits are arranged with regard to bytes.


Define Documentation

#define BYTEORDER_LSBF32 (  )     (x)

Switch the byte ordering of a float from the native swapping to Little-endian (Least Significant Byte).

If the current environment is already Little-endian, then the returned value is not byteswapped.

Parameters:
x A float.
Returns:
A float with the byte-ordering swapped if neccessary.
#define BYTEORDER_LSBF64 (  )     (x)

Switch the byte ordering of a double from the native swapping to Little-endian (Least Significant Byte).

If the current environment is already Little-endian, then the returned value is not byteswapped.

Parameters:
x A double.
Returns:
A double with the byte-ordering swapped if neccessary.
#define BYTEORDER_LSBW16 (  )     (x)

Switch the byte ordering of a short integer from the native swapping to Little-endian (Least Significant Byte).

If the current environment is already Little-endian, then the returned value is not byteswapped.

Parameters:
x A short integer.
Returns:
A short integer with the byte-ordering swapped if neccessary.
#define BYTEORDER_LSBW32 (  )     (x)

Switch the byte ordering of an integer from the native swapping to Little-endian (Least Significant Byte).

If the current environment is already Little-endian, then the returned value is not byteswapped.

Parameters:
x An integer.
Returns:
An integer with the byte-ordering swapped if neccessary.
#define BYTEORDER_MSBF32 (  )     BYTEORDER_SWAPF32(x)

Switch the byte ordering of a float from the native swapping to Big-endian (Most Significant Byte).

If the current environment is already Big-endian, then the returned value is not byteswapped.

Parameters:
x A float.
Returns:
A float with the byte-ordering swapped if neccessary.
#define BYTEORDER_MSBF64 (  )     BYTEORDER_SWAPF64(x)

Switch the byte ordering of a double from the native swapping to Big-endian (Most Significant Byte).

If the current environment is already Big-endian, then the returned value is not byteswapped.

Parameters:
x A double.
Returns:
A double with the byte-ordering swapped if neccessary.
#define BYTEORDER_MSBW16 (  )     BYTEORDER_SWAPW16(x)

Switch the byte ordering of a short integer from the native swapping to Big-endian (Most Significant Byte).

If the current environment is already Big-endian, then the returned value is not byteswapped.

Parameters:
x A short integer.
Returns:
A short integer with the byte-ordering swapped if neccessary.
#define BYTEORDER_MSBW32 (  )     BYTEORDER_SWAPW32(x)

Switch the byte ordering of an integer from the native swapping to Big-endian (Most Significant Byte).

If the current environment is already Big-endian, then the returned value is not byteswapped.

Parameters:
x An integer.
Returns:
An integer with the byte-ordering swapped if neccessary.
#define BYTEORDER_SWAPF32   byteorder_swapf32

Switch the byte ordering of a float.

Parameters:
x A float.
Returns:
A float with the byte-ordering swapped.
#define BYTEORDER_SWAPF64   byteorder_swapf64

Switch the byte ordering of a double.

Parameters:
x A double.
Returns:
A double.
#define BYTEORDER_SWAPW16 (  )     ((short)(((((unsigned short)(x))>>8)&0x00ff)+((((unsigned short)(x))<<8)&0xff00)))

Switch the byte ordering of a short integer.

Parameters:
x A short integer.
Returns:
A short integer with the byte-ordering swapped.
#define BYTEORDER_SWAPW32 (  ) 
Value:
((long)(((((unsigned long)(x))>>24L)&0x000000ff)+((((unsigned long)(x))>>8L)&0x0000ff00)+ \
                                    ((((unsigned long)(x))<<24L)&0xff000000)+((((unsigned long)(x))<<8L)&0x00ff0000)))

Switch the byte ordering of an integer.

Parameters:
x An integer.
Returns:
An integer with the byte-ordering swapped.
#define C74_BIG_ENDIAN   0

A macro that indicates whether or not the current architecture uses Big-endian byte ordering (such as is used on a PPC processor).

Note that this macro is always defined; it will be either a 0 or a 1.

#define C74_LITTLE_ENDIAN   1

A macro that indicates whether or not the current architecture uses Litte-endian byte ordering (such as is used on an i386 processor).

Note that this macro is always defined; it will be either a 0 or a 1.

Copyright © 2008, Cycling '74