
Chapter 6. Expressions and Operators
81
6.3.3 Logical Operators
A logical operator combines multiple tests and manipulates Boolean operands, then returns
the results. It is used, for example, to control the program execution flow or test the value of
an INP function bitwise, as shown in the sample below.
IF d<200 AND f<4 THEN ...
WHILE i>10 OR k<0 ...
IF NOT p THEN ...
barcod%=INP(0)AND &h02
Listed below are the four types of logical operators available.
Operations Logical Operators Precedence
Negation
Logical multiplication
Logical addition
Exclusive logical addition
NOT
AND
OR
XOR
1
2
3
4
One or more spaces or tab codes should precede and follow the NOT, AND, OR, and XOR
operators.
In the logical expressions (or operands), the logical operator first carries out the type
conversion to integers before performing the logical operation. If the resultant integer value is
out of the range from -32768 to +32767, a run-time error will occur.
If an expression contains logical operators together with arithmetic and relational operators,
the logical operators are given lowest precedence.
[ 1 ] The NOT operator
The NOT operator reverses data bits by evaluating each bit in an expression and setting the
resultant bits according to the truth table below.
Syntax: NOT expression
Truth Table for NOT
Bit in Expression Resultant Bit
0
1
1
0
For example, NOT 0 = -1 (true).
The NOT operation for an integer has the returned value of negative 1’s complement. The NOT
X, for instant, is equal to –(X+1).
Kommentare zu diesen Handbüchern