ISHA

Elemental Intrinsic Function (Generic): Arithmetically shifts an integer left or right by a specified number of bits.

Syntax

result = ISHA (i, shift)

i
(Input) Must be of type integer. This argument is the value to be shifted.


shift
(Input) 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).

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: ISHC, ISHL, ISHFT, ISHFTC

Example

  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 10100000 = -2048