IBITS (The GNU Fortran Compiler)

### 8.148 `IBITS` — Bit extraction ¶

Synopsis:

  `RESULT = IBITS(I, POS, LEN)`

Description:

  `IBITS` extracts a field of length LEN from I, starting from bit position POS and extending left for LEN bits. The result is right-justified and the remaining bits are zeroed. The value of `POS+LEN` must be less than or equal to the value `BIT_SIZE(I)`.

Class:

  Elemental function

Arguments:

  I | The type shall be `INTEGER` or `UNSIGNED`.
  POS | The type shall be `INTEGER`.
  LEN | The type shall be `INTEGER`.

Return value:

  The return value is of type as I.

Specific names:

  Name | Argument | Return type | Standard
  --- | --- | --- | ---
  `IBITS(A)` | `INTEGER A` | `INTEGER` | Fortran 90 and later
  `BBITS(A)` | `INTEGER(1) A` | `INTEGER(1)` | GNU extension
  `IIBITS(A)` | `INTEGER(2) A` | `INTEGER(2)` | GNU extension
  `JIBITS(A)` | `INTEGER(4) A` | `INTEGER(4)` | GNU extension
  `KIBITS(A)` | `INTEGER(8) A` | `INTEGER(8)` | GNU extension

Standard:

  Fortran 90 and later, has overloads that are GNU extensions. Extension for `UNSIGNED` (see Unsigned integers)

See also:

  `BIT_SIZE` — Bit size inquiry function,
  `IBCLR` — Clear bit,
  `IBSET` — Set bit,
  `IAND` — Bitwise logical and,
  `IOR` — Bitwise logical or,
  `IEOR` — Bitwise logical exclusive or