Introduction

An operator is a symbol for:

  • an arithmetic operation to be executed or

  • a logical operation to be executed or

  • a function edit (call)

Operators are generic, i.e. they adapt automatically to the data type of the operands.

Table of Operators

Operators are executed in sequence according to priority, see also Execution Sequence.

ST programming language operators:

Operator

Meaning

Order of rank

possible operands

Description

()

Use of Brackets:

1 (highest)

Expression

Brackets are used to alter the execution sequence of the operators.

Example: If the operands A, B, C and D have the values 1, 2, 3, and 4,

A+B-C*D

has the result -9 and

(A+B-C)*D

has the result 0.

FUNCNAME (Actual parameter -list)

Function processing (call)

2

Expression, Literal, Variable, Address (all data types)

Function processing is used to execute functions (see Calling Elementary Functions).

-

Negation

3

Expression, Literal, Variable, Address of Data TypeINT, DINT or REAL

During negation - a sign reversal for the value of the operand takes place.

Example: In the example OUT is -4 if IN1 is 4.

OUT := - IN1 ;

NOT

Complement

3

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, WORD or DWORD

In NOT a bit by bit inversion of the operands takes place.

Example: In the example OUT is 0011001100 if IN1 is 1100110011.

OUT := NOT IN1 ;

**

Exponentiation

4

Expression, Literal, Variable, Address of Data TypeREAL (Basis) and INT, DINT, UINT, UDINT or REAL (Exponent)

In exponentiation, ** the value of the first operand (basis) is raised to the power of the second operand (exponent).

Example: In the example OUT is 625.0 if IN1 is 5.0 and IN2 is 4.0.

OUT := IN1 ** IN2 ;

*

Multiplication

5

Expression, Literal, Variable, Address of Data TypeINT, DINT, UINT, UDINT or REAL

In multiplication, * the value of the first operand is multiplied by the value of the second operand (exponent) .

Example: In the example OUT is 20.0 if IN1 is 5.0 and IN2 is 4.0.

OUT := IN1 * IN2 ;

Note: The MULTIME function in the obsolete library is available for multiplications involving the data type Time.

/

Division

5

Expression, Literal, Variable, Address of Data TypeINT, DINT, UINT, UDINT or REAL

In division, / the value of the first operand is divided by the value of the second operand.

Example: In the example OUT is 4.0 if IN1 is 20.0 and IN2 is 5.0.

OUT := IN1 / IN2 ;

Note: The DIVTIME function in the obsolete library is available for divisions involving the data type Time.

MOD

Modulo

5

Expression, Literal, Variable, Address of Data Type INT, DINT, UINT or UDINT

For MOD the value of the first operand is divided by that of the second operand and the remainder of the division (Modulo) is displayed as the result.

Example: In this example

  • OUT is 1 if IN1 is 7 and IN2 is 2

  • OUT is 1 if IN1 is 7 and IN2 is -2

  • OUT is -1 if IN1 is -7 and IN2 is 2

  • OUT is -1 if IN1 is -7 and IN2 is -2

OUT := IN1 MOD IN2 ;

+

Addition

6

Expression, Literal, Variable, Address of Data Type INT, DINT, UINT, UDINT, REAL or TIME

In addition, + the value of the first operand is added to the value of the second operand.

Example: In this example

OUT is 9, if IN1 is 7 and IN2 is 2

OUT := IN1 + IN2 ;

-

Subtraction

6

Expression, Literal, Variable, Address of Data Type INT, DINT, UINT, UDINT, REAL or TIME

In subtraction, - the value of the second operand is subtracted from the value of the first operand.

Example: In the example OUT is 6 if IN1 is 10 and IN2 is 4.

OUT := IN1 - IN2 ;

<

Less than comparison

7

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second using <. If the value of the first operand is less than the value of the second, the result is a Boolean 1. If the value of the first operand is greater than or equal to the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is less than 10 and is otherwise 0.

OUT := IN1 < 10 ;

>

Greater than comparison

7

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second using >. If the value of the first operand is greater than the value of the second, the result is a Boolean 1. If the value of the first operand is less than or equal to the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is greater than 10, and is 0 if IN1 is less than 0.

OUT := IN1 > 10 ;

<=

Less than or equal to comparison

7

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second operand using <=. If the value of the first operand is less than or equal to the value of the second, the result is a Boolean 1. If the value of the first operand is greater than the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is less than or equal to 10, and otherwise is 0.

OUT := IN1 <= 10 ;

>=

Greater than or equal to comparison

7

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second operand using >=. If the value of the first operand is greater than or equal to the value of the second, the result is a Boolean 1. If the value of the first operand is less than the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is greater than or equal to 10, and otherwise is 0.

OUT := IN1 >= 10 ;

=

Equality

8

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second operand using =. If the value of the first operand is equal to the value of the second, the result is a Boolean 1. If the value of the first operand is not equal to the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is equal to 10 and is otherwise 0.

OUT := IN1 = 10 ;

<>

Inequality

8

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, INT, DINT, UINT, UDINT, REAL, TIME, WORD, DWORD, STRING, DT, DATE or TOD

The value of the first operand is compared with the value of the second using <>. If the value of the first operand is not equal to the value of the second, the result is a Boolean 1. If the value of the first operand is equal to the value of the second, the result is a Boolean 0.

Example: In the example OUT is 1 if IN1 is not equal to 10 and is otherwise 0.

OUT := IN1 <> 10 ;

&

Logical AND

9

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, WORD or DWORD

With &, there is a logical AND link between the operands. In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the examples OUT is 1 if IN1, IN2 and IN3 are 1.

OUT := IN1 & IN2 & IN3 ;

AND

Logical AND

9

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, WORD or DWORD

With AND, there is a logical AND link between the operands. In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the examples OUT is 1 if IN1, IN2 and IN3 are 1.

OUT := IN1 AND IN2 AND IN3 ;

XOR

Logical Exclusive OR

10

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, WORD or DWORD

With XOR, there is a logical Exclusive OR link between the operations. In the case of BYTE, WORD and DWORD data types, the link is made bit by bit.

Example: In the example OUT is 1 if IN1 and IN2 are not equal. If A and B have the same status (both 0 or 1), D is 0.

OUT := IN1 XOR IN2 ;

If more than two operands are linked, the result with an uneven number of 1-states is 1, and is 0 with an even number of 1-states.

Example: In the example OUT is 1 if 1 or 3 operands are 1. OUT is 0 if 0, 2 or 4 operands are 1.

OUT := IN1 XOR IN2 XOR IN3 XOR IN4 ;

OR

Logical OR

11 (lowest)

Expression, Literal, Variable, Address of Data Type BOOL, BYTE, WORD or DWORD

With OR, there is a logical OR link between the operands. With the BYTE and WORD, DWORD data types, the link is made bit by bit.

Example: In the example OUT is 1 if IN1, IN2 or IN3 is 1.

OUT := IN1 OR IN2 OR IN3 ;