LEADZ (The GNU Fortran Compiler)

### 8.174 `LEADZ` — Number of leading zero bits of an integer ¶

Synopsis:

  `RESULT = LEADZ(I)`

Description:

  `LEADZ` returns the number of leading zero bits of an integer.

Class:

  Elemental function

Arguments:

  I | Shall be of type `INTEGER`.

Return value:

  The type of the return value is the default `INTEGER`. If all the bits of `I` are zero, the result value is `BIT_SIZE(I)`.

Example:

      PROGRAM test_leadz
        WRITE (*,*) BIT_SIZE(1)  ! prints 32
        WRITE (*,*) LEADZ(1)     ! prints 31
      END PROGRAM

Standard:

  Fortran 2008 and later

See also:

  `BIT_SIZE` — Bit size inquiry function,
  `TRAILZ` — Number of trailing zero bits of an integer,
  `POPCNT` — Number of bits set,
  `POPPAR` — Parity of the number of bits set