pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
positions
is an INT expression that specifies the number of bit positions to shift the bit field. A value
greater than 31 gives undefined results.
The shift count must be less than the number of bits in the shifted value; therefore, you can shift an
INT value up to 15 bits left or right, and an INT(32) value up to 31 bits left or right.
The compiler reports an error if the shift count is a constant and its value is greater than the number
of bits in the value to shift.
If the shift amount is a dynamic expression and is greater than the maximum allowed (one bit less
than the number of bits being shifted), the result depends on the CHECKSHIFTCOUNT compiler
directive, as follows:
• If CHECKSHIFTCOUNT is enabled and a dynamic shift count is equal to or greater than the
number of bits in the value being shifted, the system aborts your program with an instruction
trap.
• If CHECKSHIFTCOUNT is disabled (you specify NOCHECKSHIFTCOUNT), and a dynamic
shift count is equal to or greater than the number of bits in the value being shifted, program
operation is undefined.
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 22 (page 95) to perform signed left-shift operations.
Example 22 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 40 Bit-Shift Operators
ResultRoutineOperator
Zeros fill vacated bits from the rightUnsigned left shift through bit 0'<<'
Zeros fill vacated bits from the left.Unsigned right shift'>>'
Sign bit (bit 0) unchanged; sign bit fills vacated
bits from the left
Signed right shift>>
Bit Operations 95