pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
Bit-shift operations include:
User ActionOperation
For each power of 2, shift the field one bit to the left. (Some data
might be lost.)
Multiplication by powers of 2
For each power of 2, shift the field one bit to the right (Some data
might be lost.)
Unsigned division by powers of 2
Shift the word address one bit to the left by using an unsigned
shift operator.
Word-to-byte address conversion
Bit shift examples:
1. This unsigned left shift shows how zeros fill the vacated bits from the right:
Initial value = 0 010 111 010 101 000
'<<' 2 = 1 011 101 010 100 000
2. This unsigned right shift shows how zeros fill the vacated bits from the left:
Initial value = 1 111 111 010 101 000
'>>' 2 = 0 011 111 110 101 010
3. This signed right shift shows how the sign bit fills the vacated bits from the left:
Initial value = 1 111 010 101 000 000
>> 3 = 1 111 111 010 101 000
4. These examples show multiplication and division by powers of two:
a := b << 1; ! Multiply by 2
a := b << 2; ! Multiply by 4
a := b >> 3; ! Divide by 8
a := b >> 4; ! Divide by 16
5. This unsigned bit shift converts the word address of an INT array to a byte address, which
allows byte access to the INT array:
INT a[0:5]; ! INT array>
STRING .p := @a[0] '<<' 1; ! Initialize STRING simple
! pointer with byte address
p[3] := 0; ! Access fourth byte of A
6. This example shifts the right-byte value into the left byte of the same word and sets the right
byte to a zero:
INT b; ! INT variable
b := b '<<' 8; ! Shift right-byte value into left byte
96 Expressions