Manual Reference Pages  - maskr (3fortran)

NAME

MASKR(3) - [BIT:SET] Generates a right-justified mask

SYNOPSIS

result = maskr( i [,kind] )

         elemental integer(kind=KIND) function maskr(i,KIND)

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

CHARACTERISTICS

o a kind designated as ** may be any supported kind for the type
o I is an integer
o KIND Shall be a scalar constant expression of type integer whose value is a supported integer kind.
o The result is an integer of the same kind as I unless KIND is present, which is then used to specify the kind of the result.

DESCRIPTION

MASKR(3) generates an integer with its rightmost I bits set to 1, and the remaining bits set to 0.

OPTIONS

o I : the number of right-most bits to set in the integer result. It must be from 0 to the number of bits for the kind of the result. The default kind of the result is the same as I unless the result size is specified by KIND. That is, these Fortran statements must be [char46]true. :

       i >= 0 .and. i < bitsize(i) ! if KIND is not specified
       i >= 0 .and. i < bitsize(0_KIND) ! if KIND is specified

o KIND : designates the kind of the integer result.

RESULT

The rightmost I bits of the output integer are set to 1 and the other bits are set to 0.

EXAMPLES

Sample program:

    program demo_maskr
    implicit none
    integer :: i

! basics print *,’basics’ write(*,’(i0,t5,b32.32)’) 1, maskr(1) write(*,’(i0,t5,b32.32)’) 5, maskr(5) write(*,’(i0,t5,b32.32)’) 11, maskr(11) print *,"should be equivalent on two’s-complement processors" write(*,’(i0,t5,b32.32)’) 1, shiftr(-1,bit_size(0)-1) write(*,’(i0,t5,b32.32)’) 5, shiftr(-1,bit_size(0)-5) write(*,’(i0,t5,b32.32)’) 11, shiftr(-1,bit_size(0)-11)

! elemental print *,’elemental ’ print *,’(array argument accepted like called with each element)’ write(*,’(*(i11,1x,b0.32,1x,/))’) maskr([(i,i,i=0,bit_size(0),4)])

end program demo_maskr

Results:

     >   basics
     >  1   00000000000000000000000000000001
     >  5   00000000000000000000000000011111
     >  11  00000000000000000000011111111111
     >   should be equivalent on two’s-complement processors
     >  1   00000000000000000000000000000001
     >  5   00000000000000000000000000011111
     >  11  00000000000000000000011111111111
     >   elemental
     >   (array argument accepted like called with each element)
     >            0 00000000000000000000000000000000
     >           15 00000000000000000000000000001111
     >          255 00000000000000000000000011111111
     >         4095 00000000000000000000111111111111
     >        65535 00000000000000001111111111111111
     >      1048575 00000000000011111111111111111111
     >     16777215 00000000111111111111111111111111
     >    268435455 00001111111111111111111111111111
     >           -1 11111111111111111111111111111111

STANDARD

Fortran 2008

SEE ALSO

MASKL(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 maskr (3fortran) April 28, 2024
Generated by manServer 1.08 from 6b9a68ea-c6f0-4aaf-bcdc-46fa8bbcdd9f using man macros.