pTAL Reference Manual (H06.03+)

Expressions
HP pTAL Reference Manual523746-005
5-10
Bitwise Logical Operators
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.
The Bit Operations column in Table 5-8 on page 5-10 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 2
32
-1.
Table 5-8. Bitwise Logical Operators
Operator Operation Operand Type Bit Operations Example
LOR Bitwise
logical OR
STRING, INT, or
UNSIGNED(1-16)
1 LOR 1 = 1
1 LOR 0 = 1
0 LOR 0 = 0
10 LOR 12 = 14
10 1 0 1 0
12 1 1 0 0
__ _ _ _ _
14 1 1 1 0
LAND Bitwise
logical
ADD
STRING, INT, or
UNSIGNED(1-16)
1 LAND 1 = 1
1 LAND 0 = 0
0 LAND 0 = 0
10 LAND 12 = 8
10 1 0 1 0
12 1 1 0 0
__ _ _ _ _
8 1 0 0 0
XOR Bitwise
exclusive
OR
STRING, INT, or
UNSIGNED(1-16)
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 0 = 0
10 XOR 12 = 6
10 1 0 1 0
12 1 1 0 0
__ _ _ _ _
6 0 1 1 0