Conversion and endianness functions
Type conversion
Section titled “Type conversion”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 valueSee 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.
Endianness
Section titled “Endianness”These reorder the bytes of a value when exchanging data with external systems that use a different byte order.
| Function | Parameters | Returns |
|---|---|---|
TO_BIG_ENDIAN | IN : ANY | ANY |
TO_LITTLE_ENDIAN | IN : ANY | ANY |
BIG_ENDIAN_TO | IN : ANY | ANY |
LITTLE_ENDIAN_TO | IN : ANY | ANY |
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) : ANYTO_LITTLE_ENDIAN(IN : ANY) : ANYBIG_ENDIAN_TO(IN : ANY) : ANYLITTLE_ENDIAN_TO(IN : ANY) : ANYwireValue := TO_BIG_ENDIAN(registerValue); // native -> big-endian for the wirenativeVal := BIG_ENDIAN_TO(receivedValue); // big-endian from the wire -> native