LF Fortran 95

IBITS Function

Description

The IBITS function extracts a sequence of bits from an integer argument.

Syntax

IBITS (i, pos, len)

Arguments

i is an INTENT(IN) scalar or array of type INTEGER.

pos is an INTENT(IN) scalar or array of type INTEGER. It must be non-negative.

len is an INTENT(IN) scalar or array of type INTEGER. It must be non-negative and pos+len must be less than or equal to BIT_SIZE(i).

Result

The result is of type INTEGER and of the same kind as i. Its value is the value of the sequence of len bits beginning with pos, right adjusted with all other bits set to 0.

If any argument is an array, the result is an array and has the same shape as the argument array. The value of each element is the value of the scalar operation performed on corresponding elements of any array arguments.

Note that the lowest order position starts at zero.

Example

integer :: i; data i/z'0f0f'/ write(*,"(b34)") i ! writes 111100001111 write(*,"(b34)") ibits(i,0,4) ! writes 1111 write(*,"(b34)") ibits(i,4,5) ! writes 10000

See Also

BIT_SIZE Function