184
14.3.2 Operators
Operators are used to designate how data is to be manipulated. In each statement, the operator on the left is set to the
conditions on the right. The simplest of these is the assignment operator.
Operator
Description
Example
=
Assignment Operator
preset = 77
Arithmetic operators are used for scaling and offsetting values. The priority of arithmetic operators from highest to lowest is
as follows: multiplication and division (*, /) first then modulo division (mod) and finally addition and subtraction (+, -).
Arithmetic Operators
Description
Example
+
Addition
productionTotal = good + reject
-
Subtraction
weight = Ainput - tare
*
Multiplication
scaled = flow * 0.12
/
Division
ratio = InA / InB
%
Modulo Division (returns remainder)
quarter = n % 3
Comparison operators are used for conditional statements such as If/Then or While/Wend. The priority of comparison
operators is from left to right within the statement.
Comparison Operators
Description
Example
<
Less Than
If preset < b Then preset = b
<=
Less than or Equal
If pressure < 25 Then alarm = True
>
Greater Than
If count > total Then stop = True
>=
Greater Than or Equal
While x >= 0 …statements… Wend
==
Equal
If (x mod 2) == 1 Then odd = True
<>
Not Equal
If adjust <> final Then error = 84
Logic operators are used with the other operators to make boolean (True, False) results for conditional statements. The
priority of logic operators from highest to lowest is as follows: Not, And, Or, Xor
Logic Operators
Description
Example
And
Conditional AND
If (x < b) And alarmFlag Then error = 26
Or
Conditional OR
If In1 OR In2 Then comp = 534
Xor
Conditional Exclusive Or
If error Xor 256 Then fault = True
Not
Conditional NOT
While x >= 0 And Not alarm …statements… Wend
Bitwise and Shift Operators are used to manipulate bits within char, short, and int variable types. The priority of these
operators is from left to right within the statement.
Shift Operators
Description
Example
<<
Shift left specified number of bits
z = x << 2
>>
Shift right specified number of bits
MSB = timer >> 8
Bitwise Operators
&
ANDs two values together
alarm = error & 128
|
ORs two values together
load = In1 and Out4
^
XORs two values together
a = a ^ b
~
Compliments a value
inverse = ~value
Note:
The overall priority of all operators from highest to lowest is as follows:
Operations within parenthesis are carried out first.
Arithmetic operations
Shift and Bitwise operations
Comparison Operations
Logic Operations
Assignments
Summary of Contents for MMI-1500
Page 2: ...ii...