[Home] [Prev] [Next] [Up]
SwapWord
SwapLong
SwapFloat
SwapDouble
ESwapWord
ESwapLong
ESwapFloat
ESwapDouble
NSwapWord
NSwapLong
NSwapFloat
NSwapDouble
Routines and macros for swapping the byte order of the arguments.
Usage:
#include <XDataUtil.h>
unsigned short SwapWord(unsigned short);
unsigned long SwapLong(unsigned long);
float SwapFloat(float);
double SwapDouble(double);unsigned short ESwapWord(unsigned short);
unsigned long ESwapLong(unsigned long);
float ESwapFloat(float);
double ESwapDouble(double);unsigned short NSwapWord(unsigned short);
unsigned long NSwapLong(unsigned long);
float NSwapFloat(float);
double NSwapDouble(double);
Description
The routines SwapXXX swaps the byte order from the network-native to the non-network-native order and back again.
The macros ESwapXXX swaps from the non-network-native byte order to the target platform's default byte order. This is a macro which either expands to the corrisponding SwapXXX procedure, or to null, depending on the setting of the OPT_NATIVEORDER macro.
The macros NSwapXXX swaps from the network-native byte order to the target platform's default byte order. This is a macro which either expands to the corrisponding SwapXXX procedure, or to null, depending on the setting of the OPT_NATIVEORDER macro.
Notes
The routine SwapFloat() assumes a 4-byte floating point value. The routine SwapDouble() assumes an 8-byte floating point value. While the 4-byte float is the default on the Metrowerks Codewarrior product (as well as in Visual C++), the 8-byte double is not the default in the 680x0 Macintosh C++ compiler.
Which means use with caution.
No such problem exists for the SwapWord or SwapLong routines.