[COMPUTE] result = [BIT-NOT] operand1
[{BIT-AND|BIT-OR|BIT-XOR} [BIT-NOT] operand2
[{BIT-AND|BIT-OR|BIT-XOR} [BIT-NOT] operand3
... ]].
In a bit expression, an operand operand1 can be linked with one or more operands - operand2, operand3, and so on - using bit operators; parentheses are possible. Bit expressions can only be used in the COMPUTE statement.
The operands operand can be byte-type data objects, functional methods with byte-type return values, or compound bit expressions. The bit operators BIT-AND, BIT-OR, and BIT-XOR link two adjacent operands. When the expression is evaluated, a byte-type value is calculated and linked with the next adjacent operand. The priority of the link depends on the operators that are used; if you use functional methods, the same applies as described for arithmetic expressions.
You can specify the bit operator BIT-NOT one or more times
before an operand to negate the value of the operand. If BIT-NOT
is specified an even number of times, the operand remains unchanged. An odd number of uses negates the operand.
If a single data object is specified as an operand without a preceding bit operator
BIT-NOT, this is not a complete bit expression. In this case, the
COMPUTE statement has the same effect as the MOVE statement.
Bit sequences are an efficient way of mapping set operations. If a set contains n elements, the existence of an element i in n can be represented by a 1 at the position of i in a byte-type field. You can use the SET BIT statement, amongst others, to add an element to the set. The operators BIT-AND, BIT-OR, and BIT-XOR can then be used to calculate the average quantity, the union quantity, and the symmetrical difference of different sets.
In the following example, the attributes of person groups - for example - are mapped in the fields p1, p2, p3 of the type x. The bit operator BIT-AND is then used to determine which attributes are shared by all people. The result shows that only the eighth attribute is shared.
DATA:
res TYPE x LENGTH 1,
p1 TYPE x LENGTH 1 VALUE '5B', "01011011
p2 TYPE x LENGTH 1 VALUE '13', "00010011
p3 TYPE x LENGTH 1 VALUE 'A5'. "10100101
res = p1 BIT-AND p2 BIT-AND p3. "00000001
Non-Catchable Exceptions