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

Example 18 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 19 Bit Extraction From an Array
STRING right_byte;
INT array[0:7];
right_byte := array[5].<8:15>;
Example 20 (page 94) assigns bits 4 through 7 of the sum of two numbers to RESU<. The
parentheses cause the numbers to be added before the bits are extracted.
Example 20 Modifying Bits Before Extracting Them
INT result;
INT num1 := 51;
INT num2 := 28;
result := (num1 + num2).<4:7>;
Example 21 (page 94) checks bit 15 for a nonzero value.
Example 21 Checking a Bit for a Nonzero Value
STRING var;
IF var.<15> THEN ... ;
Bit Shifts
A bit shift operation shifts a bit field a specified number of positions to the left or to the right within
a variable without altering the variable. RISC and Itanium architectures do not include a signed
left-shift operation, so pTAL compiles a signed left shift (for example, i << 8) as an unsigned left
shift (i '<<' 8).
int-expression
is an INT arithmetic expression. int-expression can contain STRING, INT, or
UNSIGNED(1-16) operands. The bit shift occurs within a word.
dbl-expression
is an INT(32) arithmetic expression. dbl-expression can contain INT(32) or
UNSIGNED(17-31) operands. The bit shift occurs within a doubleword.
shift-operator
is one of the operators described in Table 23 (page 70).
94 Expressions