ISHFTC(3) - [BIT:SHIFT] Shift rightmost bits circularly, AKA. a logical shift
result = ishftc( i, shift [,size] )
elemental integer(kind=KIND) function ishftc(i, shift, size)integer(kind=KIND),intent(in) :: i integer(kind=**),intent(in) :: shift integer(kind=**),intent(in),optional :: size
o a kind designated as ** may be any supported kind for the type o I may be an integer of any kind o SHIFT and SIZE may be integers of any kind o the kind for I dictates the kind of the returned value.
ISHFTC(3) circularly shifts just the specified rightmost bits of an integer.
ISHFTC(3) returns a value corresponding to I with the rightmost SIZE bits shifted circularly SHIFT places; that is, bits shifted out one end of the section are shifted into the opposite end of the section.
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.
o I : The value specifying the pattern of bits to shift o SHIFT : If SHIFT is positive, the shift is to the left; if SHIFT is negative, the shift is to the right; and if SHIFT is zero, no shift is performed. The absolute value of SHIFT must be less than SIZE (simply put, the number of positions to shift must be less than or equal to the number of bits specified to be shifted).
o SIZE : The value must be greater than zero and less than or equal to BIT_SIZE(i). The default if BIT_SIZE(I) is absent is to circularly shift the entire value I.
The result characteristics (kind, shape, size, rank, ...) are the same as I.
The result has the value obtained by shifting the SIZE rightmost bits of I circularly by SHIFT positions.
No bits are lost.
The unshifted bits are unaltered.
Sample program:
program demo_ishftc use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 implicit none integer :: i character(len=*),parameter :: g=(b32.32,1x,i0) ! basics write(*,*) ishftc(3, 1), <== typically should have the value 6Results:print *, lets start with this: write(*,(b32.32))huge(0) print *, shift the value by various amounts, negative and positive do i= -bit_size(0), bit_size(0), 8 write(*,g) ishftc(huge(0),i), i enddo print *,elemental i=huge(0) write(*,*)ishftc(i,[2,3,4,5]) write(*,*)ishftc([2**1,2**3,-2**7],3) print *,note the arrays have to conform when elemental write(*,*)ishftc([2**1,2**3,-2**7],[5,20,0])
end program demo_ishftc
> 6 <== typically should have the value 6 > lets start with this: > 01111111111111111111111111111111 > shift the value by various amounts, negative and positive > 01111111111111111111111111111111 -32 > 11111111111111111111111101111111 -24 > 11111111111111110111111111111111 -16 > 11111111011111111111111111111111 -8 > 01111111111111111111111111111111 0 > 11111111111111111111111101111111 8 > 11111111111111110111111111111111 16 > 11111111011111111111111111111111 24 > 01111111111111111111111111111111 32 > elemental > -3 -5 -9 -17 > 16 64 -1017 > note the arrays have to conform when elemental > 64 8388608 -128
Fortran 95
Fortran intrinsic descriptions (license: MIT) @urbanjost
o ISHFT(3) - Logical shift of bits in an integer o SHIFTA(3) - Right shift with fill o SHIFTL(3) - Shift bits left o SHIFTR(3) - Combined right shift of the bits of two int... o DSHIFTL(3) - Combined left shift of the bits of two inte... o DSHIFTR(3) - Combined right shift of the bits of two int... o CSHIFT(3) - Circular shift elements of an array o EOSHIFT(3) - End-off shift elements of an array
Nemo Release 3.1 | ishftc (3fortran) | November 02, 2024 |