TAL Reference Manual
Expressions
TAL Reference Manual—526371-001
4-31
Examples of Bit Shifts
3. This signed left shift shows how zeros fill the vacated bits from the right, while the
sign bit remains the same (TNS systems only):
Initial value = 1 011 101 010 100 000
<< 1 = 1 111 010 101 000 000
4. 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
5. 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
6. 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
7. 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