Lahey/Fujitsu Fortran

BTEST Function

Description

The BTEST function will test the bit in position pos in an INTEGER data object.

Syntax

BTEST (i, pos)

Arguments

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

pos is an INTENT(IN) scalar or array of type INTEGER. It must be non-negative and less than BIT_SIZE (i). Bits are numbered from least significant to most significant, beginning with 0.

If both i and pos are arrays, they must be conformable.

Result

The result is of type default LOGICAL.

If both i and pos are scalar, BTEST returns the value true if bit pos has the value 1 and false if bit pos has the value zero.

If i is scalar and pos is an array, the result is a LOGICAL array the same shape as pos. Each element of the array contains the result of testing i for each bit position contained in each element of pos.

If i is an array and pos is scalar, the result is a LOGICAL array the same shape as i. Each element of the array contains the result of testing bit position pos for each element of array i.

If i and pos are conformable arrays, The result is a LOGICAL array the same shape as i. Each element of the array contains the result of testing each element of i using the bit position from the corresponding element of pos.

Example

integer :: i=-1,j=4,spos=bit_size(i)-1 integer :: k(4)=(/1,2,4,8/),pos(4)=(/0,1,2,3/) write(*,*) btest(i,spos),btest(j,spos) ! test sign bit write(*,*) btest(i,pos) ! test first 4 bits of i write(*,*) btest(k,2) ! test bit #2 for each element of k write(*,*) btest(k,pos) ! test each element of k using the ! corresponding element of pos