Logical Operators
Logical operators make logical comparisons. Normally, they are used in IF/THEN
statements to make a logical test between two ormore relations. For example:
IFA
= 1
OR
C=
2
THEN PRINT X
The logical operator, OR, compares the two relations A = I and C = 2.
Logical operators may also be used to make bit-comparisons
of
two numeric
expressions.
Forthis application,
BASIC does a bit-by-bitcomparison
of
the two operands,
according to predefined rules for the specific operator.
Note:
The
operands are converted to integertype, stored internally as 16-bit,
two's
complementnumbers. To understand the results
of
bit-by-bit
comparisons, you need to keep this in mind.
Thefollowing table summarizes the action
of
Boolean operators in bit
manipulation.
Meaning
of
First
Second
Operator
Operation
Operand
Operand
Result
AND
Whenboth bits are 1, the 1
1
I
result will be 1. Otherwise, 1
0
0
the result will be
O.
0
1 0
0
0 0
OR
Result will be 1unless both 1 1
1
bits are
O.
1 0 1
0
1 1
0 0 0
NOT
Result is opposite
of
bit. 1 0
0
1
1/25