196
Manual – IPOSplus®
15
Binary operators
Compiler – Operators
15.3 Binary operators
These operators link two operands together and are located between two operands.
15.3.1 Example
Combined assignment operators lead to an abbreviated notation. Although they make it
more difficult to read a program, they are mentioned for the sake of completeness. The
operation is performed in the example with H1 = 2 (0b10) and H2 =3 (0b11).
15.4 Ternary operators
The IPOS
plus®
Compiler only recognizes one operator that links together three oper-
ands: The conditional operator. Its form is as follows:
a ? b : c means: If a then b, otherwise c
where a is a logical expression and b and c are expressions.
15.4.1 Example
The example is the abbreviated notation of:
Where possible, the ternary operator should not be used due to the illegibility of the
source code.
H1 = H2; // The binary assignment operator (=) assigns variable H1 the value of H2
H1 = H2 - 3; // The binary minus operator (-) forms the difference between H2 and 3
Operator Operation Example Corresponds to Example H1
=
= Simple assignment H1 = H2; H1 = H2; 3
*= Assign product H1 *= H2; H1 = H1 * H2; 6
/= Assign quotient H1 /= H2; H1 = H1/H2; 0
%= Assign remainder H1%= H2: H1 = H1% H2; 2
+= Assign sum H1 += H2; H1 = H1 + H2; 5
-= Assign difference H1 -= H2; H1 = H1 - H2; -1
&= Assign bit-by-bit AND H1 &= H2; H1 = H1 & H2; 0b10
^= Assign bit-by-bit XOR H1 ^= H2; H1 = H1 ^ H2; 0b01
¦= Assign bit-by-bit OR H1 ¦= H2; H1 = H1 ¦ H2; 0b11
<<= Assign shift left H1 <<= H2; H1 = H1 << H2; 0b1000
> > = Assign arithmetical shift right H1 >>= H2; H1 = H1 >> H2; 0b0
H1 = H2 == 3 ? H3 : H4; // If H2 equals 3, H1 is assigned the value of
H3,
// otherwise it is assigned the value H4
if (H2 == 3)
H1 = H3;
else
H1 = H4;