btest(x, pos): Bit Test at Position

Teste de bit.

Declaration

Sintaxe

retval = btest(x, pos);
elemental logical function btest(x, pos)

Argumentos

x and pos are integer input values. Both input values are of same kind. pos represents position in x.

Valores de retorno

The return value is of type logical.

Descrição

btest(x, pos) calculates if pos bit in input integer value x is set. The counting of the bits starts at 0, at least significant bit (LSB) i.e., the rightmost bit in x.

If pos less than 0 or greater than bit_size(), btest(x, pos) errors with not allowed message.

Tipos

Supported input types is integer of 32 bit and 64 bit size.

interface btest
    module procedure btest32, btest64
end interface

contains

interface
    elemental logical function btest32(x, pos)
	integer(int32), intent(in) :: x
	integer, intent(in) :: pos
	end function

    elemental logical function btest64(x, pos)
	integer(int64), intent(in) :: x
	integer, intent(in) :: pos
	end function
end interface

Exemplos

program intrinsics_btest
    implicit none
    print *, btest(2, 0)
end program

Resultado:

false

Veja Também