Pages

Sunday, November 29, 2009

Relational Operators for Bit Patterns

The table below shows the relational operators for comparisons of operands with bit patterns in byte-like operands. The data type of the right operand operand2 must be byte-like (x or xstring). It contains the bit pattern to which the left operand operand1 is compared. If operand1 is shorter than operand2, hexadecimal zeroes are appended to the right of operand1 to lengthen it appropriately. However, no conversion takes place.

In Unicode programs, the data type of operand1 must also be byte-like (x or xstring). Outside of Unicode programs, operand1 can be of any elementary data type or have a flat structure.

The logical expression in the IF statement is false, because before the comparison, hex1 is lengthened to the right with 00. If the content of hex2 was 111100, then the comparison would be true.

DATA: hex1 TYPE xstring,
hex2 TYPE xstring.

hex1 = 'FFFF'.
hex2 = '111111'.

IF hex1 O hex2.
...
ENDIF.

Operator Meaning
O Ones: True if the bits that are 1 in operand2, are also 1 in operand1. If operand2 contains only zeroes, the logical expression is always true.
Z Zeros: True, if the bits that are 1 in operand2 are 0 in operand1. If operand2 contains only zeroes, the logical expression is always true.
M Mixed: True, if of the bits that are 1 in operand2, at least one is 1 and one is 0 in operand1. If operand2 contains only zeroes, the logical expression is always false.

No comments:

Post a Comment