PLC bit expressions and statements

Language reference ›› Statements ›› Assignments and expressions ››
Parent Previous Next

If the {$BITMODE PLC} directive is used, the compiler switches to a special bit expressions and statements mode.

All operators or function calls are supported in bit expressions except the negate operator.

The difference in bit expressions, is that the * operator (multiply) is interpreted as an alias of AND, the + operator (add) as an alias of OR and the / operator is an alias of NOT, so that expressions like ones used in PLCs may be used, with a quite compact form.

In PLC mode, non-boolean terms are allowed, but special attention have to be observed about math implying the changed operators.



{$BITMODE PLC} // PLC MODE = one-bit mode
Out1 := (/In1 + In2) * In3 * (Value1 < 2); // Equivalent to: (NOT In1 OR In2) AND In3 AND (Value1 < 2);
{$BITMODE OFF} // NORMAL MODE


{ Note: operator * has the maximum precedence in expressions evaluations, so: }
Out1 := In1 + In2 * In3 + In4;
{ Is equivalent to: }
Out1 := In1 + (In2 * In3) + In4;
{ Weird expression: }
Out1 := In1 + (Value1 * Value2) < 2; // Equivalent to: In1 OR (Value1 AND Value2) < 2;