pTAL Conversion Guide

Bit Operations
pTAL Conversion Guide527302-002
14-2
pTAL
pTAL
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 native compiler reports an error if the shift count is a constant and the shift-count
value is greater than the number of bits in the value to shift.
i := a '<<' 8; ! OK: result is %HCD00%
i := a '<<' 63; ! OK: result is %H0000%
i := a '<<' 64; ! ERROR: 64 is too large
i := a >> 8; ! OK: result is %HFFAB%
i := a >> 63; ! OK: result is %HFFFF%
i := a '>>' 8; ! OK: result is %H00AB%
i := a '>>' 63; ! OK: result is %H0000%
i := a << count1; ! OK: result is %H8000%
i := a '<<' count1; ! OK: result is %H0000%
i := a << count2; ! OK: result is %HCD00%
i := a '<<' count2; ! OK: result is %HCD00%
i := a >> count2; ! OK: result is %HFFAB%
i := a '>>' count2; ! OK: result is %H00AB%
--32-Bit Operands
i32 := b << 8; ! OK: result is %HCDEF6300%D
i32 := b << 63; ! OK: result is %H80000000%D
i32 := b '<<' 8; ! OK: result is %HCDEF6300%D
i32 := b '<<' 63; ! OK: result is %H00000000%D
i32 := b '<<' 64; ! ERROR: 64 is too large
i32 := b >> 8; ! OK: result is %HFFABCDEF%D
i32 := b >> 63; ! OK: result is %HFFFFFFFF%D
i32 := b '>>' 8; ! OK: result is %H00ABCDEF%D
i32 := b '>>' 63; ! OK: result is %H00000000%D
i32 := b << count2; ! OK: result is %HCDEF3600%D
i32 := b '<<' count2; ! OK: result is %HCDEF3600%D
i32 := b >> count2; ! OK: result is %HFFABCDEF%D
i32 := b '>>' count2; ! OK: result is %H00ABCDEF%D
Example 14-1. TAL Shift Operations (page 2 of 2)