Manual Reference Pages  - poppar (3fortran)

NAME

POPPAR(3) - [BIT:COUNT] Parity of the number of bits set

SYNOPSIS

result = poppar(i)

         elemental integer function poppar(i)

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

CHARACTERISTICS

o I is an integer of any kind
o the return value is a default kind integer

DESCRIPTION

POPPAR(3) returns the parity of an integer’s binary representation (i.e., the parity of the number of bits set).

The parity is expressed as
o 0 (zero) if I has an even number of bits set to 1.
o 1 (one) if the number of bits set to one 1 is odd,

OPTIONS

o I : The value to query for its bit parity

RESULT

The return value is equal to 0 if I has an even number of bits set and 1 if an odd number of bits are set.

EXAMPLES

Sample program:

    program demo_poppar
    use, intrinsic :: iso_fortran_env, only : integer_kinds, &
       & int8, int16, int32, int64
    implicit none
    character(len=*),parameter :: pretty=’(b64,1x,i0)’
       ! basic usage
       print pretty, 127,     poppar(127)
       print pretty, 128,     poppar(128)
       print pretty, int(b"01010"), poppar(int(b"01010"))

! any kind of an integer can be used print pretty, huge(0_int8), poppar(huge(0_int8)) print pretty, huge(0_int16), poppar(huge(0_int16)) print pretty, huge(0_int32), poppar(huge(0_int32)) print pretty, huge(0_int64), poppar(huge(0_int64)) end program demo_poppar

Results:

     >                                                          1111111 1
     >                                                         10000000 1
     >                                                             1010 0
     >                                  1111111111111111111111111111111 1
     >                                                          1111111 1
     >                                                  111111111111111 1
     >                                  1111111111111111111111111111111 1
     >  111111111111111111111111111111111111111111111111111111111111111 1

STANDARD

Fortran 2008

SEE ALSO

There are many procedures that operator or query values at the bit level:

POPCNT(3), LEADZ(3), TRAILZ(3) ATOMIC_AND(3), ATOMIC_FETCH_AND(3), ATOMIC_FETCH_OR(3), ATOMIC_FETCH_XOR(3), ATOMIC_OR(3), ATOMIC_XOR(3), BGE(3), BGT(3), BIT_SIZE(3), BLE(3), BLT(3), BTEST(3), DSHIFTL(3), DSHIFTR(3), IALL(3), IAND(3), IANY(3), IBCLR(3), IBITS(3), IBSET(3), IEOR(3), IOR(3), IPARITY(3), ISHFTC(3), ISHFT(3), MASKL(3), MASKR(3), MERGE_BITS(3), MVBITS(3), NOT(3), SHIFTA(3), SHIFTL(3), SHIFTR(3), STORAGE_SIZE(3)

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


Nemo Release 3.1 poppar (3fortran) April 28, 2024
Generated by manServer 1.08 from a55a6a68-d17c-468e-98f7-6706e19cf669 using man macros.