pTAL Reference Manual (H06.08+)
Expressions
HP pTAL Reference Manual—523746-006
5-34
Bit Shifts
The compiler implements arithmetic left shifts as unsigned left shifts (and warns you
when it does this).
Most programs do not need to perform signed left shifts. If your program does require
an arithmetic left shift, use the functions in Example 5-12 on page 5-34 to perform
signed left-shift operations.
Example 5-12. Arithmetic Left Shift
INT PROC ashift16(a, count);
INT a, count;
BEGIN
STRUCT s = a;
BEGIN
UNSIGNED(1) sign_bit;
UNSIGNED(15) rest;
END;
s.rest := s.rest '<<' count;
RETURN a;
END;
INT(32) PROC ashift32(a, count);
INT(32) a;
INT count;
BEGIN
STRUCT s = a;
BEGIN
UNSIGNED(1) sign_bit;
UNSIGNED(31) rest;
END;
s.rest := s.rest '<<' count;
RETURN a;
END;
Table 5-18. Bit-Shift Operators
Operator Routine Result
'<<' Unsigned left shift
through bit 0
Zeros fill vacated bits from the right
'>>' Unsigned right shift Zeros fill vacated bits from the left.
>> Signed right shift Sign bit (bit 0) unchanged; sign bit fills vacated bits
from the left










