8.215 POPCNT — Number of bits set

Description:

POPCNT(I) returns the number of bits set (’1’ bits) in the binary representation of I.

Standard:

Fortran 2008 and later

Class:

Elemental function

Syntax:

RESULT = POPCNT(I)

Arguments:
IShall be of type INTEGER.
Return value:

The return value is of type INTEGER and of the default integer kind.

Example:
program test_population
  print *, popcnt(127),       poppar(127)
  print *, popcnt(huge(0_4)), poppar(huge(0_4))
  print *, popcnt(huge(0_8)), poppar(huge(0_8))
end program test_population
See also:

POPPAR — Parity of the number of bits set,
LEADZ — Number of leading zero bits of an integer,
TRAILZ — Number of trailing zero bits of an integer