pTAL Reference Manual (G06.24+, H06.09+, J06.03+)

Bitwise Logical Operators
Use bitwise logical operators (LOR, LAND, and XOR) to perform bit-by-bit operations on STRING,
INT, UNSIGNED(1-16) operands. Use INT(32) operands to return INT(32) results. 16-bit operands
produce a 16-bit result. 32-bit operands produce a 32-bit result. Bitwise logical operators are not
defined for 64-bit operands.
Table 30 Bitwise Logical Operators
ExampleBit OperationsOperand TypeOperationOperator
10 LOR 12 = 14
10 1 0 1 0
1 LOR 1 = 1
1 LOR 0 = 1
0 LOR 0 = 0
STRING, INT, or
UNSIGNED(1-16)
Bitwise logical
OR
LOR
12 1 1 0 0
__ _ _ _ _
14 1 1 1 0
10 LAND 12 = 8
10 1 0 1 0
1 LAND 1 = 1
1 LAND 0 = 0
0 LAND 0 = 0
STRING, INT, or
UNSIGNED(1-16)
Bitwise logical
ADD
LAND
12 1 1 0 0
__ _ _ _ _
8 1 0 0 0
10 XOR 12 = 6
10 1 0 1 0
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 0 = 0
STRING, INT, or
UNSIGNED(1-16)
Bitwise exclusive
OR
XOR
12 1 1 0 0
__ _ _ _ _
6 0 1 1 0
The Bit Operations column in Table 30 (page 76) shows the bit-by-bit operations that occur on
16-bit values. Each 1-bit operand pair results in a 1-bit result. The bit operands are commutative.
Using Bitwise Logical Operators and INT(32) Operands
You can use INT(32) operands with:
Logical operators (LOR, LAND, and XOR)
The following example swaps the values stored in i and j:
INT(32) i;
INT(32) j;
i := i XOR j;
j := i XOR j;
i := i XOR j;
Unsigned relational operators ('<', '<=', '=', '<>', '>=', and '>').
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1.
Unsigned addition and subtraction operators ('+' and '-')
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1.
Unsigned and signed addition and subtraction are the same except that $OVERFLOW
(page 335) returns false after an unsigned operation.
Unsigned multiplication operator ('*')
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1. The unsigned
product of two INT(32) values is an FIXED value. $OVERFLOW (page 335) returns false after
an unsigned multiplication operator.
Unsigned division and remainder operators ('/' and '\')
You can use an FIXED dividend and INT(32) divisor with the unsigned-division and remainder
operators. The FIXED dividend is treated as a nonnegative value in the range 0 to 264-1. The
INT(32) divisor is treated as a nonnegative value in the range 0 to 232-1.
76 Expressions