]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
2 | Copyright 1988-2022 Free Software Foundation, Inc. | |
3 | This is part of the GCC manual. | |
4 | For copying conditions, see the copyright.rst file. | |
5 | ||
6 | .. index:: POPCNT, binary representation, bits set | |
7 | ||
8 | .. _popcnt: | |
9 | ||
10 | POPCNT --- Number of bits set | |
11 | ***************************** | |
12 | ||
13 | .. function:: POPCNT(I) | |
14 | ||
15 | ``POPCNT(I)`` returns the number of bits set ('1' bits) in the binary | |
16 | representation of ``I``. | |
17 | ||
18 | :param I: | |
19 | Shall be of type ``INTEGER``. | |
20 | ||
21 | :return: | |
22 | The return value is of type ``INTEGER`` and of the default integer | |
23 | kind. | |
24 | ||
25 | Standard: | |
26 | Fortran 2008 and later | |
27 | ||
28 | Class: | |
29 | Elemental function | |
30 | ||
31 | Syntax: | |
32 | .. code-block:: fortran | |
33 | ||
34 | RESULT = POPCNT(I) | |
35 | ||
36 | Example: | |
37 | .. code-block:: fortran | |
38 | ||
39 | program test_population | |
40 | print *, popcnt(127), poppar(127) | |
41 | print *, popcnt(huge(0_4)), poppar(huge(0_4)) | |
42 | print *, popcnt(huge(0_8)), poppar(huge(0_8)) | |
43 | end program test_population | |
44 | ||
45 | See also: | |
46 | :ref:`POPPAR`, | |
47 | :ref:`LEADZ`, | |
3ed1b4ce | 48 | :ref:`TRAILZ` |