The group of logical operators NOT, AND, OR, and XOR is required for expressions of the type Boolean on the one hand, and for numbers of the type Short, Integer, or Long (-Integer) on the other. The logical operators form the basis for efficient comparisons and bit manipulation functions. Special cases apply to character strings and objects in logical negation with the NOT operator. Setting parentheses affects the ranking of operations if several logical operators are used.
|NOT expression0||Calculates the logical NOT of the expression (from True to False and vice versa) or a number based on the binary representation of this number.|
|Expression1 AND Expression2||Calculates the logical AND of two Boolean expressions or the numeric AND of two integer numbers based on the binary representation of these numbers.|
|Expression1 OR Expression2||Calculates the logical OR of two Boolean type expressions or the numerical OR of two integer numbers based on the binary representation of these numbers.|
|Expression1 XOR Expression2||Calculates the logical XOR of two Boolean expressions or the numerical XOR of two integer numbers based on the binary representation of these numbers.|
Table 8.4.1: Logical operators for Boolean or numeric expressions
The numbers are of the type Boolean Short, Integer or Long (-Integer). The calculation with the used logical operator is based on the bitwise logical operation of the binary representation of the numbers on the basis of the so-called truth tables.
The operator inverts each bit in the binary representation of the number, as shown in the following table and examples:
|Bit 1||Bit 2||Not Bit 1||Bit 1||Bit1 AND Bit2 AND Bit2||Bit1 OR Bit1 OR Bit2||Bit1 XOR Bit2||Bit1 XOR Bit2|
Table 184.108.40.206: Logical operators and truth table
Print 13;; Bin(13, 8);; Bin(Not 13, 8);; NOT 13 13 00001101 11110010 -14 Print 5;; 12;; Bin(5, 8);; Bin(12, 8);; Bin(5 AND 12, 8);; 5 AND 12 5 12 00000101 00001100 00000100 4 Print 5;; 12;; Bin(5, 8);; Bin(12, 8);; Bin(5 OR 12, 8);; 5 OR 12 5 12 00000101 00001100 00001101 13 Print 5;; 12;; Bin(5, 8);; Bin(12, 8);; Bin(5 XOR 12, 8);; 5 XOR 12 5 12 00000101 00001100 00001001 9
Chapter 9.9 Bit manipulation introduces functions that consistently work with the presented logical operators.
If the operand after the unary logical operator NOT is a string (string) or an object, the following applies to NOT expression: If the expression is a string or an object, True is returned if the expression is zero or False if the expression is NOT zero.
Sub Picture_Write(pPicture As Picture) If NOT pPicture Then pPicture = HorizontalFader.DefaultPicture MyOriginalPicture = pPicture If MyOriginalPicture Then GetPictures Me.Draw End