DSHIFTL(3) - [BIT:COPY] Combined left shift of the bits of two integers
result = dshiftl(i, j, shift)
elemental integer(kind=KIND) function dshiftl(i, j, shift)integer(kind=KIND),intent(in) :: i integer(kind=KIND),intent(in) :: j integer(kind=**),intent(in) :: shift
o the kind of I, J, and the return value are the same. An exception is that one of I and J may be a BOZ literal constant (A BOZ literal constant is a binary, octal or hex constant). o If either I or J is a BOZ-literal-constant (but not both), it is first converted as if by the intrinsic function INT(3) to type integer with the kind type parameter of the other. o a kind designated as ** may be any supported kind for the type
DSHIFTL(3) combines bits of I and J. The rightmost SHIFT bits of the result are the leftmost SHIFT bits of J, and the remaining bits are the rightmost BITSIZE(I)-SHIFT of I.
Hence DSHIFTL is designated as a "combined left shift", because it is like we appended I and J together, shifted it SHIFT bits to the left, and then kept the same number of bits as I or J had.
For example, for two 16-bit values if SHIFT=6
SHIFT=6 I = 1111111111111111 J = 0000000000000000 COMBINED 11111111111111110000000000000000 DROP LEFT BITS 11111111110000000000000000 KEEP LEFT 16 1111111111000000
This is equivalent to
ior( shiftl(i, shift), shiftr(j, bit_size(j) - shift) )Also note that using this last representation of the operation is can be derived that when both I and J have the same value as in
dshiftl(i, i, shift)the result has the same value as a circular shift:
ishftc(i, shift)
o I : used to define the left pattern of bits in the combined pattern o J : used for the right pattern of bits in the combined pattern o SHIFT : shall be nonnegative and less than or equal to the number of bits in an integer input value (ie. the bit size of either one that is not a BOZ literal constant).
The leftmost SHIFT bits of J are copied to the rightmost bits of the result, and the remaining bits are the rightmost bits of I.
Sample program:
program demo_dshiftl use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 implicit none integer(kind=int32) :: i, j integer :: shiftResults:! basic usage write(*,*) dshiftl (1, 2**30, 2) ! int32 values on little-endian => 5
! print some simple calls as binary to better visual the results i=-1 j=0 shift=5 call printit()
! the leftmost SHIFT bits of J are copied to the rightmost result bits j=int(b"11111000000000000000000000000000") ! and the other bits are the rightmost bits of I i=int(b"00000000000000000000000000000000") call printit()
j=int(b"11111000000000000000000000000000") i=int(b"00000111111111111111111111111111") ! result should be all 1s call printit()
contains subroutine printit() ! print i,j,shift and then i,j, and the result as binary values write(*,(*(g0)))I=,i, J=,j, SHIFT=,shift write(*,(b32.32)) i,j, dshiftl (i, j, shift) end subroutine printit
end program demo_dshiftl
> 5 > I=-1 J=0 SHIFT=5 > 11111111111111111111111111111111 > 00000000000000000000000000000000 > 11111111111111111111111111100000 > I=0 J=-134217728 SHIFT=5 > 00000000000000000000000000000000 > 11111000000000000000000000000000 > 00000000000000000000000000011111 > I=134217727 J=-134217728 SHIFT=5 > 00000111111111111111111111111111 > 11111000000000000000000000000000 > 11111111111111111111111111111111
Fortran 2008
DSHIFTR(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | dshiftl (3fortran) | November 02, 2024 |