Skip to content

Conversion and endianness functions

Conversion between data types is provided by a large, rule-generated family of functions (INT_TO_REAL, REAL_TRUNC_INT, BYTE_BCD_TO_INT, …). Rather than listing the hundreds of generated names here, the naming rules and the type set they range over are documented on the dedicated type conversion page — once you know the rule, you know the function name.

Every conversion function takes a single input parameter named IN of the source type and returns the target type:

<FROM>_TO_<TO>(IN : <FROM>) : <TO>
r := INT_TO_REAL(counter);
b := REAL_TO_BYTE(level);
whole := REAL_TRUNC_INT(3.9); // 3, not 4 (truncates)
value := BYTE_BCD_TO_INT(thumbwheel); // decode a BCD value

See the type conversion page for the <FROM>_TO_<TO> general rule, the <REAL>_TRUNC_<TO> truncating rule, the _BCD_TO_ / _TO_BCD_ rules and the full source/target type set.

These reorder the bytes of a value when exchanging data with external systems that use a different byte order.

FunctionParametersReturns
TO_BIG_ENDIANIN : ANYANY
TO_LITTLE_ENDIANIN : ANYANY
BIG_ENDIAN_TOIN : ANYANY
LITTLE_ENDIAN_TOIN : ANYANY

TO_BIG_ENDIAN / TO_LITTLE_ENDIAN convert a native value to the named byte order; BIG_ENDIAN_TO / LITTLE_ENDIAN_TO convert from the named byte order back to the native representation.

TO_BIG_ENDIAN(IN : ANY) : ANY
TO_LITTLE_ENDIAN(IN : ANY) : ANY
BIG_ENDIAN_TO(IN : ANY) : ANY
LITTLE_ENDIAN_TO(IN : ANY) : ANY
wireValue := TO_BIG_ENDIAN(registerValue); // native -> big-endian for the wire
nativeVal := BIG_ENDIAN_TO(receivedValue); // big-endian from the wire -> native