ISHA (integer, shift)
Class: Elemental function - Generic
Arithmetically shifts an integer left or right by a specified
number of bits.
The "shift" is of type integer; it is the direction and distance of
shift.
The result type is the same as "integer".
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. If the shift is to the left, zeros are shifted in on the
right. If the shift is to the right, copies of the sign bit (0 for
non-negative "integer"; 1 for negative "integer") are shifted in on
the left.
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).
Examples:
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