[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]

EXAMPLES:

"A" < "B" result true (-1)
"X" = "YY" result false (0)
BB$ <> CC$

Numeric data items can only be compared (or assigned) to other numeric items. The same is true when comparing strings, otherwise the BASIC error message ?TYPE MISMATCH will occur. Numeric operands are compared by first converting the values of either or both operands from integer to floating-point form, as necessary. Then the relationship of the floating- point values is evaluated to give a true/false result.

At the end of all comparisons, you get an integer no matter what data type the operand is (even if both are strings). Because of this, a comparison of two operands can be used as an operand in performing calculations. The result will be - 1 or 0 and can be used as anything but a divisor, since division by zero is illegal.

LOGICAL OPERATORS

The logical operators (AND, OR, NOT) can be used to modify the meanings of the relational operators or to produce an arithmetic result. Logical operators can produce results other than -1 and 0, though any nonzero result is considered true when testing for a true/false condition.

The logical operators (sometimes called Boolean operators) can also be used to perform logic operations on individual binary digits (bits) in two operands. But when you're using the NOT operator, the operation is performed only on the single operand to the right. The operands must be in the integer range of values (-32768 to +32767) (floating-point numbers are converted to integers) and logical operations give an integer result.

Logical operations are performed bit-by-corresponding-bit on the two operands. The logical AND produces a bit result of 1 only if both operand bits are 1. The logical OR produces a bit result of I if either operand bit is 1. The logical NOT is the opposite value of each bit as a single operand. In other words, it's really saying, "if it's NOT 1 then it is 0. If it's NOT 0 then it is 1."

The exclusive OR (XOR) doesn't have a logical operator but it is performed as part of the WAIT statement. Exclusive OR means that if the bits of two operands are equal then the result is 0 otherwise the result is 1.

Logical operations are defined by groups of statements which, taken together, constitute a Boolean "truth table" as shown in Table 1-2.


[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated November 13, 1998.