9.3.73 ISHA (I, SHIFT)

Description:  Arithmetically shifts an integer left or right by a specified number of bits. 
Class:  Elemental function; Generic 
Arguments:  I Must be of type integer. This argument is the value to be shifted. 
  SHIFT Must be of type integer. This argument is the direction and distance of shift.

Positive shifts are left (toward the most significant bit); negative shifts are right (toward the least significant bit).
Results:  The result type is the same as I. The result is equal to I shifted arithmetically by SHIFT bits.

If SHIFT is positive, the shift is to the left; if SHIFT is negative, the shift is to the right. If SHIFT is zero, no shift is performed.

Bits shifted out from the left or from the right, as appropriate, are lost. Zeros are shifted in from the opposite end.

The kind of integer is important in arithmetic shifting because sign varies among integer representations (see the following example). If you want to shift a one-byte or two-byte argument, you must declare it as INTEGER(1) or INTEGER(2).


Consider the following:

INTEGER(1) i, res1
INTEGER(2) j, res2
i = -128             ! equal to  10000000
j = -32768           ! equal to  10000000 00000000
res1  = ISHA (i, -4) ! returns 11111000 = -8
res2  = ISHA (j, -4) ! returns 11111000 00000000 = -2048

Previous Page Next Page Table of Contents