Logic
Test
this
by
entering:
100
REMark
NOT
and
brackets
110
PRINT
"Enter
two
values"\"1
for
TRUE
or
0
for
FALSE"
120
INPUT
"tall";
tall
130
INPUT
"fa;
r";
fa;
r
140
IF
NOT
<taLL
AND
fair)
THEN
PRINT
"FIRST"
150
IF
NOT
tat
L
OR
NOT
fai
r
THEN
PRINT "SECOND"
Whatever combination of numbers you give
as
Inpu\,
the output will always be either
two
words
or
none, never
one.
This
will
suggest
that
the
two
compound logical
expresSions
are equivalent.
•
XOR-Exclusive
OR
Suppose a golf professional wanted an assistant who could either run the shop or give
golf
lessons.
If
an applicant turned
up
with both abilities he might not get the job because
the golf professional might fear that such
an
able assistant would
try
to
take over He
would accept a good golfer who could not
run
the
shop.
He would also accept a poor
golfer who could run the shop. This
IS
an
exclusive
OR
situation: either
is
acceptable
but not both. The
follOWing
program would
test
applicants:
100
REMark
XOR
test
110
PRINT
"Enter
1
for
yes
or
0
for
no."
120
INPUT
"Can you run a
shop?",
shop
130
INPUT
"Can
you
teach
goLf?",
golf
140
IF
shop
XOR
goLf
THEN
PRINT
"SuitabLe"
The only combinations of answers that
will
cause the output ''Suitable'' are
(0
and
1)
or
(1
and
0).
The rules
for
XOR are given
below.
•
Able to run shop
FALSE
FALSE
TRUE
TRUE
Able to teach
FALSE
TRUE
FALSE
TRUE
Shop XOR teach
FALSE
TRUE
TRUE
FALSE
effect
no
Job
gets the job
gets the job
no
Job
rules
for
XOR
S6
PRIORITIES
The order of priority for the logical operators
IS
(highest
first):
NOT
AND
OR,XOR
For
example the expression
nch
OR
tall
AND fair
means the same
as:
rich
OR
(tall
AND
fair)
The AND operation
IS
performed
first.
To
prove that the two logical expressions have
identical effects run the following program:
100
REMark
Priorities
110
PRINT
llEnter
three
valuesll\"Type
1
for
Yes and 0
for
NO"I
120 INPUT
rich,tall,fair
130
IF
ri
ch
OR
taL
LAND
fai
r
THEN
PRINT
"YES"
140
IF
ri
ch
OR
<taL
LAND
fai
r)
THEN
PRINT "AYE"
Whatever combination of three zeroes or ones
you
input
at
line 120 the output will be
either nothing
or:
YES
AYE
You
can make sure that
you
test
all
pOSSibilities
by
entenng data which forms eight three-
digit binary numbers 000
to
111:
000
001
010
011 100 101 110 111
12/84
•