Routines (alphabetical) > Routines: B > BYTEORDER

# BYTEORDER

The BYTEORDER procedure converts integers between host and network byte ordering or floating-point values between the native format and XDR (IEEE) format. This routine can also be used to swap the order of bytes within both short and long integers. If the type of byte swapping is not specified via one of the keywords below, bytes within short integers are swapped (even and odd bytes are interchanged).

The size of the parameter, in bytes, must be evenly divisible by two for short integer swaps, and by four for long integer swaps. BYTEORDER operates on both scalars and arrays. The parameter must be a variable, not an expression or constant, and may not contain strings. The contents of Variable are overwritten by the result.

Network byte ordering is “big endian”. That is, multiple byte integers are stored in memory beginning with the most significant byte.

## Syntax

BYTEORDER, Variable1, ..., Variablen [, /DTOVAX] [, /DTOXDR] [, /FTOVAX] [, /FTOXDR] [, /HTONL] [, /HTONS] [, /L64SWAP] [, /LSWAP] [, /NTOHL] [, /NTOHS] [, /SSWAP] [, /SWAP_IF_BIG_ENDIAN] [, /SWAP_IF_LITTLE_ENDIAN] [, /VAXTOD] [, /VAXTOF] [, /XDRTOD] [, /XDRTOF]

## Arguments

### Variablen

A named variable (not an expression or constant) that contains the data to be converted. The contents of Variable are overwritten by the new values.

## Keywords

### DTOVAX

Set this keyword to convert native (IEEE) double-precision floating-point format to VAX D float format.

### DTOXDR

Set this keyword to convert native double-precision floating-point format to XDR (IEEE) format.

### FTOVAX

Set this keyword to convert native (IEEE) single-precision floating-point format to VAX F float format.

### FTOXDR

Set this keyword to convert native single-precision floating-point format to XDR (IEEE) format.

### HTONL

Set this keyword to perform host to network conversion, longwords.

### HTONS

Set this keyword to perform host to network conversion, short integers.

### L64SWAP

Set this keyword to perform a 64-bit swap (8 bytes). Swap the order of the bytes within each 64-bit word. For example, the eight bytes within a 64-bit word are changed from (B0, B1, B2, B3 B4, B5, B6, B7), to (B7, B6, B5, B4, B3, B2, B1, B0).

### LSWAP

Set this keyword to perform a 32-bit longword swap. Swap the order of the bytes within each longword. For example, the four bytes within a longword are changed from (B0, B1, B2, B3), to (B3, B2, B1, B0).

### NTOHL

Set this keyword to perform network to host conversion, longwords.

### NTOHS

Set this keyword to perform network to host conversion, short integers.

### SSWAP

Set this keyword to perform a short word swap. Swap the bytes within short integers. The even and odd numbered bytes are interchanged. This is the default action, if no other keyword is set.

### SWAP_IF_BIG_ENDIAN

If this keyword is set, the BYTEORDER request will only be performed if the platform running IDL uses “big endian” byte ordering. On little endian machines, the BYTEORDER 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 BYTEORDER request will only be performed if the platform running IDL uses “little endian” byte ordering. On big endian machines, the BYTEORDER 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.

### VAXTOD

Set this keyword to convert VAX D float format to native (IEEE) double-precision floating-point format.

### VAXTOF

Set this keyword to convert VAX F float format to native (IEEE) single-precision floating-point format.

### XDRTOD

Set this keyword to convert XDR (IEEE) format to native double-precision floating-point.

### XDRTOF

Set this keyword to convert XDR (IEEE) format to native single-precision floating-point.

### Thread Pool Keywords

This routine is written to make use of IDL’s thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

## Note on Accessing Data in VAX Floating Point Format

When converting between VAX and IEEE formats, you should be aware of the following basic numerical issues in order to get the best results. Translation of floating-point values from IDL’s native IEEE format to the VAX format and back (that is, VAX to IEEE to VAX) is not a completely reversible operation, and should be avoided when possible. There are many cases where the recovered values will differ from the original values, including:

- The VAX floating-point format lacks support for the IEEE special values (NaN and Infinity). Hence, their special meaning is lost when they are converted to VAX format and cannot be recovered.
- The IEEE and VAX floating formats have intrinsic differences in precision and range, which can cause information to be lost in both directions. When converting from one format to another, IDL rounds the value to the nearest representable value in the target format.

As a practical matter, an initial conversion of existing VAX format data to IEEE cannot be avoided if the data is to be used on modern machines. However, each format conversion can add a small amount of error to the resulting values, so it is important to minimize the number of such conversions. Use IEEE/VAX conversions only to read existing VAX format data, and create all new files using the native IEEE format. This introduces only a single unavoidable conversion, and minimizes the resulting conversion error.

## Version History

Pre 4.0 | Introduced
Pre 6.1 | Deprecated DTOGFLOAT and GFLOATTOD keywords

## See Also

SWAP_ENDIAN