Logical Operators. Commodore CBM 2001, PET 2001-8, CBM 8000, CBM 4000, CBM 3000
تبلیغات
تبلیغات
1.8.3 Logical Operators
Logical operators perform tests on multiple relations, bit manipulation, or Boolean operations.
The logical operator returns a bitwise result which is either "true" (not zero) or "false" (zero).
In an expression, logical operations are performed after arithmetic and relational operations.
The outcome of a logical operation is determined as shown in the following table. The operators are listed in order of precedence.
NOT
•
1
0
NOT
0
1
AND
•
0
0
1
1
Y X AND Y
1
0
1
0
0
0
0
1
OR
•
0
0
1
1 0
0
Y XORY
1
1
0
1
1
1
Just as the relational operators can be used to make decisions regarding program flow, logical operators can connect two or more relations and return a true or false value to be used in a decision (see IF, Section 2.24). For example:
IF D<200 AND F<4 THEN 80 IF
1>10 OR K<O THEN 50 IF NOT
P THEN 100
Logical operators work by converting their operands to sixteen bit, signed, two's complement integers in the range -32768 to +32767. (If the operands are not in this range, an error results.) If both operands are supplied as 0 or -1, logical operators return 0 or -1. The given operation is performed on these integers in bitwise fashion, i.e., each bit of the result is determined by the corresponding bits in the two operands.
17
دانلود
تبلیغات