BASIC Logical Operators - fvdhoef/aquarius-plus GitHub Wiki

NOT

TYPE: BASIC Logical Operator

FORMAT: NOT numeric

Action:

The NOT logical operator "complements" the value of each bit in its single operand, producing an integer "twos-complement" result. In other words, the NOT is really saying, "if it isn't. When working with a floating-point number, the operands are converted to integers and any fractions are lost. The NOT operator can also be used in a comparison to reverse the true/false value which was the result of a relationship test and therefore it will reverse the meaning of the comparison. In the first example below, if the "twos-complement" of "AA" is equal to "BB" and if "BB" is NOT equal to "CC" then the expression is true.

Examples:
10 IF NOT AA = BB AND NOT(BB = CC) THEN...
NN = NOT 96: PRINT NN
-97

NOTE: To find the value of NOT use the expression X=(-(X+1)). The two's complement of any integer is the bit complement plus one.


AND

TYPE: BASIC Logical Operator

FORMAT: numeric AND numeric

Action:

Action: AND is used in Boolean operations to test bits. It is also used in operations to check the truth of both operands.

In Boolean algebra, the result of an AND operation is 1 only if both numbers being ANDed are 1. The result is 0 if either or both is 0 (false).

Single Bit AND Operations
            0         1         0         1
        AND 0     AND 0     AND 1     AND 1
       ------     -----     -----     -----
            0         0         0         1

The Aquarius performs the AND operation on numbers in the range from -32768 to +32767. Any fractional values are not used, and numbers beyond the range will cause an ?ILLEGAL QUANTITY error message. When converted to binary format, the range allowed yields 16 bits for each number. Corresponding bits are ANDed together, forming a 16-bit result in the same range.

Integer AND Operations
                                17
                           AND 194
                          --------
                  0000000000010001
              AND 0000000011000010
        --------------------------
         (BINARY) 0000000000000000
        --------------------------
        (DECIMAL)                0
                             32007
                         AND 28761
                        ----------
                  0111110100000111
              AND 0111000001011001
        --------------------------
         (BINARY) 0111000000000001
        --------------------------
        (DECIMAL)            28673
                              -241
                         AND 15359
                        ----------
                  1111111100001111
              AND 0011101111111111
        --------------------------
         (BINARY) 0011101100001111
        --------------------------
        (DECIMAL)            15119

When evaluating a number for truth or falsehood, the computer assumes the number is true as long as its value isn't 0. When evaluating a comparison, it assigns a value of -1 if the result is true, while false has a value of 0. In binary format, -1 is all 1's and 0 is all 0's. Therefore, when ANDing true/false evaluations, the result will be true if any bits in the result are true.

Examples:
  50 IF X=7 AND W=3 THEN GOTO 10: REM ONLY TRUE IF BOTH X=7 AND W=3 ARE TRUE
  60 IF A AND Q=7 THEN GOTO 10: REM TRUE IF A IS NON-ZERO AND Q=7 IS TRUE

OR

TYPE: BASIC Logical Operator

FORMAT: operand OR operand

Action:

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 which can then be used in a decision. When used in calculations, the logical OR gives you a bit result of 1 if the corresponding bit of either or both operands is 1. This will produce an integer as a result depending on the values of the operands. When used in comparisons the logical OR operator is also used to link two expressions into a single compound expression. If either of the expressions are true, the combined expression value is true (-1). In the first example below if AA is equal to BB OR if XX is 20, the expression is true.

Logical operators work by converting their operands to 16-bit, signed, two's complement integers in the range of -32768 to +32767. If the operands are not in the range an error message results. Each bit of the result is determined by the corresponding bits in the two operands.

Examples:
100 IF (AA=BB) OR (XX=20) THEN...
230 KK%=64 OR 32: PRINT KK%

You typed this with a bit value of 1000000 for 64 and 100000 for 32

96 The computer responds with bit value 1100000. 1100000=96.

⚠️ **GitHub.com Fallback** ⚠️