ISHFT(3) - [BIT:SHIFT] Logical shift of bits in an integer
result = ishftc( i, shift )
elemental integer(kind=KIND) function ishft(i, shift )integer(kind=KIND),intent(in) :: i integer(kind=**),intent(in) :: shift
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.
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.
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.
The result has the value obtained by shifting the bits of I by SHIFT positions.
Bits shifted out from the left or from the right, as appropriate, are lost. Zeros are shifted in from the opposite end.
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.
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)Results: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
> 6 <== typically should have the value 6 > 11111111111111111111111111110000 4 > 01111111111111111111111111111111 0 > 00000111111111111111111111111111 -4
Fortran 95
ISHFTC(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | ishft (3fortran) | November 02, 2024 |