pTAL Conversion Guide

pTAL Conversion Guide527302-002
14-1
14 Bit Operations
This section describes differences between bit operations in TAL and pTAL.
Topics:
Shift Operations on page 14-1
Using 32-Bit Operands With Bit Deposit and Bit Extract Operations on page 14-4
Shift Operations
Topics:
TAL on page 14-1
pTAL on page 14-2
TAL
If the shift count is a constant or constant expression, the TAL compiler reports an error
if the shift count is greater than or equal to 64. If the shift count is less than 64, the shift
operator shifts its operand by the number of bits specified by the shift count. Shift
operators do not perform modulo arithmetic on the shift count—if you shift an INT value
by more than 15 bits or an INT(32) value by more than 31 bits, the result is 0 except for
signed shifts, which do not alter the sign bit.
If the shift count is a dynamic expression, its value can be in the range 0 through
65535. A TNS process shifts the value by the shift count modulo 256.
You can perform a signed or unsigned, left or right shift on any STRING, INT, or
INT(32) value. TNS architecture supports four types of shifts:
INT i;
i := i << 8; ! Signed left shift 8 bits
i := i '<<' 8; ! Unsigned left shift 8 bits
i := i >> 8; ! Signed right shift 8 bits
i := i '>>' 8; ! Unsigned right shift 8 bits
Example 14-1. TAL Shift Operations (page 1 of 2)
INT count1 := 24,
count2 := 264; ! 264 is used as 8 (264 mod 256)
INT i;
INT a := %HABCD%;
INT(32) i32
INT(32) b := %HABCDEF63%D;
--16-Bit Operands
i := a << 8; ! OK: result is %HCD00%
i := a << 63; ! OK: result is %H8000%