Modern Pascal Boolean Operators
Logical Operators
Boolean Operators actually applies to every if evaluation, while and repeat until evaluation, let alone, bit masks. The following table shows all the Boolean operators supported by Pascal language. All these operators work on Boolean operands and produce Boolean results.Assume variable A holds true and variable B holds false, then:
Operator |
Description | Example |
And | Called Boolean AND operator. If both the operands are true, then condition becomes true. | (A and B) is false |
Or | Called Boolean OR Operator. If any of the two operands is true, then condition becomes true. | (A or B) is true |
Xor | Called Boolean XOR Operator, Exclusive OR. Results in a value of true if and only if exactly one of the operands has a value of true. | (A xor B) is true |
Not | Called Boolean NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. | not (A or B) is true |
Bit Operators
Bitwise operators work on bits and perform bit-by-bit operation. All these operators work on integer operands and produces integer results.Assume variable P holds 60 and variable Q holds 13, then:
Operator |
Description | Example | Result |
And | P is 0011 1100 Q is 0000 1101 = 0000 1100 |
(P and Q) | 12 |
Or | P is 0011 1100 Q is 0000 1101 = 0011 1101 |
(P or Q) |
63 |
Xor | P is 0011 1100 Q is 0000 1101 = 0011 0001 |
(P xor Q) | 49 |
Not | P is 0011 1100 Q is 0000 1101 = 1111 0011 |
not (P and Q) |
243 |
Pascal uses And, Or, Xor and Not for both logical evaluations and bit operations. There will be times that you must clarify with parenthesis to group your logic of thinking otherwise you will get a compilation error, as the code could be interpreted as with bit operation or logical expression.
var a:longint; s:string; begin if a=0 and s='' then ...
When most pascal compilers see that if expression, since you have not grouped with parenthesis, will try to evaluate as a=(0 and S) and raise an error because the next token is =. A few compiler authors will attempt different pattern parsing techniques to guess the AND is between two expressions. However, we suggest that your code look more like:
var a:longint; s:string; begin if (a=0) and (s='') then ...