btest(x, pos):位置位测试

位测试。

声明

语法

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

参数

xpos 是整数输入值。 两个输入值是同一种类型。 pos 表示在 x 中的位置。

返回值

返回值是逻辑类型。

描述

btest(x, pos) 计算输入整数值 x 中的 pos 位是否已设置。 位的计数从 0 开始,至少是有效位 (LSB),即“x”中的最右边位。

如果 pos 小于 0 或大于 bit_size(),则 btest(x, pos) 错误并显示不允许的消息。

类型

支持的输入类型是 32 位和 64 位大小的整数。

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

示例

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

结果:

false

也可以看看