Setting byte order
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Setting byte order
When passing MEMPTR data between system
environments (such as can happen using sockets), you must help ensure that
the communicating applications agree on the byte order for any data
types that are transferred using the MEMPTR variable.
Most machines follow one of two schemes for ordering bytes:
-
Little-endian — Low-order bytes are stored starting
at the lowest address location reserved for a data type, with progressively higher-order
bytes stored at the higher byte positions. For example, 7 is stored
in a four-byte (hex) integer as follows, where addresses increase from
left to right:
07 00 00 00 -
Big-endian — High-order bytes are stored in the lowest address
location reserved for a data type with progressively lower-order bytes
stored at the higher byte positions. For example, 7 is stored in
a four-byte (hex) integer as follows, where addresses increase from
left to right:
00 00 00 07
ABL ensures that MEMPTR data is interpreted
correctly using MEMPTR write/read statements and
functions as long as you indicate what byte order the MEMPTR data
that you write uses. To do this use the SET-BYTE-ORDER statement:
Syntax
|
Given the name of the MEMPTR variable (memptr-name),
you can set one of these keyword values for integer-expression:
-
HOST-BYTE-ORDER— A value of one (1) that indicates the byte ordering of the machine where the statement executes -
BIG-ENDIAN— A value of two (2) that indicates big-endian byte orderingNote: Internet protocols use big-endian byte ordering. -
LITTLE-ENDIAN— A value of three (3) that indicates little-endian byte ordering
By default, all MEMPTR variables use the byte
ordering of the machine where they are defined.
Note that the SET-BYTE-ORDER statement does
not change the existing order of bytes in the MEMPTR data.
It only indicates how subsequent MEMPTR write/read
statements and functions interpret the data. You can also return
the current byte order setting using the GET-BYTE-ORDER function.
For more information, see ABL Reference.