Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ISHA

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

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 and kind are 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. 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 i; 1 for negative i) 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).

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

See Also