Sharp OZ-707 Operation Manual - Page 28

Relational Expressions, Logical Expressions

Page 28 highlights

Note: String quantities and numeric quantities cannot be combined in the same expression unless one of the functions that convert a string value into a numeric value or vice versa is used: "15" + 10 is illegal "15" + "10" is "1510", not "25" Relational Expressions A relational expression compares two expressions and determines whether the stated relationship is true or false. The relational operators are: > Greater than > = Greater than or Equal to = Equal to < > Not equal to < = Less than or Equal to < Less than The following are valid relational expressions: A = 5 0(3) < > 8 If A was equal to 10, B equal to 12, C(1,2) equal to 6, and 0(3) equal to 9, all of these relational expressions would be true. Character strings can also be compared in relational expressions. The two strings are compared character by character according to their ASCII value starting at the first character (see Appendix B). If one string is shorter than the other, a 0 or NULL will be used for any missing positions. All of the following relational expressions are true: "ABCDEF" = "ABCDEF" "ABCDEF" < > "ABCDE" "ABCDEF" > "ABCDE" Relational expressions evaluate to true or false. The Card represents true by a -1; false is represented by a O. 44 r Logical Expressions Logical operations use the Boolean algebra functions AND. OR. XOR and NOT to build connections between relational expressions. The logical operations in a single expression are evaluated after arithmetic and relational operations. In this way. logical operators can be used to make program decisions based on multiple conditions using the IF ... THEN ... ELSE statement. Example: IF A < = 32 AND B > = 90 THEN 150 This statement causes execution to jump to line number 150 if the value of the numeric variable A is less than or equal to 32 and at the same time, the value of numeric variable B is greater than or equal to 90. IF X < > 13 OR Y = 0 THEN 50 This statement causes execution to jump to line 50 unless variable X has the value 13, or if variable Y is equal to O. In a logical operation involving two numbers in the range -32768 to +32767, the two numbers are converted into 16-bit binary integers (in two's complement form) and the logical connection is then evaluated for each corresponding pair of bits in the two numbers. The results returned by the logical operators for these bit evaluations are listed here: AND OR XOR NOT XY XANDY 11 1 10 0 o1 0 00 0 XY X ORY 11 1 10 1 o1 1 00 0 XY XXORY 11 0 10 1 o1 1 00 0 X NOT X 1 0 0 1 After each bit pair has returned the corresponding result (a 1 or a 0) according to the above tables, the resulting 16-bit binary number is converted back to a decimal value. This number is the result of the logical operation. 45

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128

r
Note:
String quantities and numeric quantities cannot be combined in the
same expression unless one of the functions that convert a string value
into a numeric value or vice versa
is
used:
"15" +
10
is
illegal
"15" + "10" is "1510", not "25"
Relational Expressions
A relational expression compares two expressions
and
determines
whether the stated relationship is true or false. The relational operators
are:
>
Greater than
>
=
Greater than or Equal to
=
Equal to
<
>
Not equal to
<
=
Less than or Equal
to
<
Less than
The following are valid relational expressions:
A<B
C(1,2)
>
=
5
0(3)
<
>
8
If A was equal to 10, B equal
to
12, C(1,2) equal
to
6,
and 0(3) equal
to
9,
all of these relational expressions would be true.
Character strings can also
be
compared
in
relational expressions. The
two strings are compared character by character according to their
ASCII value starting at the first character (see Appendix B). If one
string is shorter than the other, a 0 or NULL will
be
used for any
missing positions. All of the following relational expressions are true:
"ABCDEF"
=
"ABCDEF"
"ABCDEF"
<
>
"ABCDE"
"ABCDEF"
>
"ABCDE"
Relational expressions evaluate to true or false. The Card represents
true by a
-1;
false
is
represented by a
O.
44
Logical Expressions
Logical operations use the Boolean algebra functions AND. OR. XOR
and NOT to build connections between relational expressions. The
logical operations
in
a single expression are evaluated after arithmetic
and relational operations.
In
this way. logical operators can be used to make program decisions
based on multiple conditions using the
IF
... THEN ... ELSE statement.
Example:
IF A
<
=
32 AND B
>
=
90 THEN 150
This statement causes execution
to
jump to line number 150 if the
value of the numeric variable A is less than or equal to 32 and at the
same time, the value of numeric variable B is greater than or equal to
90.
IF X
< >
13 OR Y
=
0 THEN 50
This statement causes execution
to
jump to line 50 unless variable
X
has the value
13,
or if variable
Y
is
equal to
O.
In
a logical operation involving two numbers
in
the range
-32768
to
+32767, the two numbers are converted into 16-bit binary integers
(in
two's complement form) and the logical connection
is
then evaluated
for each corresponding pair of bits
in
the two numbers.
The results returned
by
the logical operators for these bit evaluations
are listed here:
AND
OR
XOR
NOT
XY
XANDY
XY
X
ORY
XY
XXORY
X
NOT
X
1 1
1
1 1
1
1 1
0
1
0
1 0
0
1
0
1
1 0
1
0
o
1
0
o
1
1
o
1
1
00
0
00
0
00
0
After each bit pair has returned the corresponding result (a 1
or
a
0)
according to the above tables, the resulting 16-bit binary number is
converted back to a decimal value. This number is the result of the
logical operation.
45
1