Binary Operators
A binary operator is an operator that performs an operation on two operands. One operand is to the left of the operator and one is to the right of the operator.
Arithmetic
Arithmetic operators perform mathematical calculations on numerical operands.
- Addition (
+): Adds two operands. - Subtraction (
-): Subtracts the second operand from the first. - Multiplication (
*): Multiplies two operands. - Division (
/): Divides the first operand by the second. - Exponentiation (
**): Raises the first operand to the power of the second. - Modulus
MOD: Calculates the remainder of the division of two operands.
VAR
a : INT := 6;
b : INT := 3;
END_VAR
print(a + b); // 9
print(a - b); // 3
print(a * b); // 18
print(a / b); // 2
print(a ** b); // 216
print(a MOD b); // 0
Comparison
Comparison operators compare two operands and return a boolean value (TRUE or FALSE).
- Equal to (
=): Checks if two operands are equal. - Not equal to (
<>): Checks if two operands are not equal. - Greater than (
>): Checks if the first operand is greater than the second. - Less than (
<): Checks if the first operand is less than the second. - Greater than or equal to (
>=): Checks if the first operand is greater than or equal to the second. - Less than or equal to (
<=): Checks if the first operand is less than or equal to the second.
VAR
a : INT := 6;
b : INT := 3;
END_VAR
print(a = b); // FALSE
print(a <> b); // TRUE
print(a > b); // TRUE
print(a < b); // FALSE
print(a >= b); // TRUE
print(a <= b); // FALSE
Logical
Logical operators perform logical operations on boolean values.
- AND (
AND): Returns TRUE if both operands are TRUE. - OR (
OR): Returns TRUE if at least one operand is TRUE. - XOR (
XOR): Returns TRUE if exactly one of the operands is TRUE.
VAR
a : BOOL := TRUE;
b : BOOL := FALSE;
END_VAR
print(a AND b); // FALSE
print(a OR b); // TRUE
print(a XOR b); // TRUE
Bitwise
Bitwise operators perform operations on the binary representations of integers.
- Bitwise AND (
AND): Performs a bitwise and operation. - Bitwise OR (
OR): Performs a bitwise or operation. - Bitwise XOR (
XOR): Performs a bitwise exclusive or operation.
VAR
a : INT := 6; // 0110 in binary
b : INT := 3; // 0011 in binary
END_VAR
print(a AND b); // 2 (0010 in binary)
print(a OR b); // 7 (0111 in binary)
print(a XOR b); // 5 (0101 in binary)