pTAL Reference Manual (H06.08+)

Expressions
HP pTAL Reference Manual523746-006
5-32
Bit Extractions
You can perform bit extractions and deposits on 16-bit and 32-bit items. pTAL reports
an error, however, if you attempt to reference bits outside of the bits declared in the
variables declaration.
Example 5-10 on page 5-32 assigns bits 4 through 7 of the sum of two numbers to
RESULT. The parentheses cause the numbers to be added before the bits are
extracted.
Example 5-11 on page 5-32 checks bit 15 for a nonzero value.
Example 5-8. Bit Extraction
INT i;
UNSIGNED(4) j;
STRING k;
INT(32) l;
i := j.<7:11>; ! ERROR: You can reference only bits 12
! through 15 of j
i := k.<0:7>; ! ERROR: You can reference only bits 8
! through 15 of k
i := l.<8:31>; ! OK: You can reference any of bits 0
! through 31 of l
Example 5-9. Bit Extraction From an Array
STRING right_byte;
INT array[0:7];
right_byte := array[5].<8:15>;
Example 5-10. Modifying Bits Before Extracting Them
INT result;
INT num1 := 51;
INT num2 := 28;
result := (num1 + num2).<4:7>;
Example 5-11. Checking a Bit for a Nonzero Value
STRING var;
IF var.<15> THEN ... ;