Manual Reference Pages  - ishft (3fortran)

NAME

ISHFT(3) - [BIT:SHIFT] Logical shift of bits in an integer

SYNOPSIS

result = ishftc( i, shift )

         elemental integer(kind=KIND) function ishft(i, shift )

integer(kind=KIND),intent(in) :: i integer(kind=**),intent(in) :: shift

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o I is an integer of any kind. the kind for I dictates the kind of the returned value.
o SHIFT is an integer of any kind.

DESCRIPTION

ISHFT(3) returns a value corresponding to I with all of the bits shifted SHIFT places left or right as specified by the sign and magnitude of SHIFT.

Bits shifted out from the left end or right end are lost; zeros are shifted in from the opposite end.

OPTIONS

o I : The value specifying the pattern of bits to shift
o SHIFT : A value of SHIFT greater than zero corresponds to a left shift, a value of zero corresponds to no shift, and a value less than zero corresponds to a right shift.

If the absolute value of SHIFT is greater than BIT_SIZE(I), the value is undefined.

RESULT

The result has the value obtained by shifting the bits of I by SHIFT positions.
1. If SHIFT is positive, the shift is to the left
2. if SHIFT is negative, the shift is to the right
3. 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.

EXAMPLES

Sample program:

    program demo_ishft
    use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
    implicit none
    integer             :: shift
    character(len=*),parameter :: g=’(b32.32,1x,i0)’

write(*,*) ishft(3, 1),’ <== typically should have the value 6’

shift=4 write(*,g) ishft(huge(0),shift), shift shift=0 write(*,g) ishft(huge(0),shift), shift shift=-4 write(*,g) ishft(huge(0),shift), shift end program demo_ishft

Results:

    >              6  <== typically should have the value 6
    >   11111111111111111111111111110000 4
    >   01111111111111111111111111111111 0
    >   00000111111111111111111111111111 -4

STANDARD

Fortran 95

SEE ALSO

ISHFTC(3)

Fortran intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 ishft (3fortran) November 02, 2024
Generated by manServer 1.08 from c364c995-e724-4588-b94f-226a0267d3da using man macros.