ISHFT

Elemental Intrinsic Function (Generic): Performs a logical shift.

Syntax

result = ISHFT (i, shift)

i
(Input) Must be of type integer.

shift
(Input) Must be of type integer. The absolute value for shift must be less than or equal to BIT_SIZE(i).

Results

The result type is the same as i. The result has the value obtained by shifting the bits of i  by shift positions. 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.

ISHFT with a positive shift  can also be specified as LSHIFT (or LSHFT). ISHFT with a negative shift  can also be specified as RSHIFT (or RSHFT) with |shift|.

For more information on bit functions, see Bit Functions.

The model for the interpretation of an integer value as a sequence of bits is shown in Model for Bit Data.

Specific Name Argument Type Result Type
BSHFT INTEGER(1) INTEGER(1)
IISHFT 1 INTEGER(2) INTEGER(2)
JISHFT INTEGER(4) INTEGER(4)
KISHFT INTEGER(8) INTEGER(8)
1 Or HSHFT.

See Also

BIT_SIZE, ISHFTC, ISHA, ISHC

Examples

ISHFT (2, 1) has the value 4.

ISHFT (2, -1) has the value 1.

The following shows another example:

  INTEGER(1) i, res1
  INTEGER(2) j, k(3), res2
  i = 10 ! equal to 00001010
  j = 10 ! equal to 00000000 00001010
  res1 = ISHFT (i, 5)  ! returns 01000000 = 64
  res2 = ISHFT (j, 5)  ! returns 00000001 01000000 =
                       ! 320

  k = ISHFT((/3, 5, 1/), (/1, -1, 0/))  ! returns array
                                        ! /6, 2, 1/