The SWAP_ENDIAN_INPLACE procedure reverses the byte ordering of arbitrary scalars, arrays or structures. It can make “big endian” number “little endian” and vice-versa.
Note: The BYTEORDER procedure can be used to reverse the byte ordering of scalars and arrays (SWAP_ENDIAN_INPLACE also allows structures).
SWAP_ENDIAN_INPLACE differs from the SWAP_ENDIAN function in that it alters the input data in place rather than making a copy as does SWAP_ENDIAN. SWAP_ENDIAN_INPLACE can therefore be more efficient, if a copy of the data is not needed. The pertinent bytes in the input variable are reversed.
This routine is written in the IDL language. Its source code can be found in the file swap_endian_inplace.pro in the lib subdirectory of the IDL distribution.
Examples
Reverse the byte order of A:
SWAP_ENDIAN_INPLACE, A
Syntax
SWAP_ENDIAN_INPLACE, Variable [, /SWAP_IF_BIG_ENDIAN] [, /SWAP_IF_LITTLE_ENDIAN]
Arguments
Variable
The named variable—scalar, array, or structure—to be swapped.
Keywords
SWAP_IF_BIG_ENDIAN
If this keyword is set, the swap request will only be performed if the platform running IDL uses “big endian” byte ordering. On little endian machines, the SWAP_ENDIAN_INPLACE request quietly returns without doing anything. Note that this keyword does not refer to the byte ordering of the input data, but to the computer hardware.
SWAP_IF_LITTLE_ENDIAN
If this keyword is set, the swap request will only be performed if the platform running IDL uses “little endian” byte ordering. On big endian machines, the SWAP_ENDIAN_INPLACE request quietly returns without doing anything. Note that this keyword does not refer to the byte ordering of the input data, but to the computer hardware.
Version History
See Also
BYTEORDER, SWAP_ENDIAN