| 1 |
# btest(x, pos): Bit Test at Position |
| 2 |
|
| 3 |
Bit test. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = btest(x, pos); |
| 11 |
elemental logical function btest(x, pos) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` and `pos` are integer input values. Both input values are of same kind. |
| 17 |
`pos` represents position in `x`. |
| 18 |
|
| 19 |
### Return values |
| 20 |
|
| 21 |
The return value is of type logical. |
| 22 |
|
| 23 |
## Description |
| 24 |
|
| 25 |
`btest(x, pos)` calculates if `pos` bit in input integer value `x` is set. The |
| 26 |
counting of the bits starts at 0, at least significant bit (LSB) i.e., the |
| 27 |
rightmost bit in `x`. |
| 28 |
|
| 29 |
If `pos` less than 0 or greater than `bit_size()`, `btest(x, pos)` errors with |
| 30 |
not allowed message. |
| 31 |
|
| 32 |
## Types |
| 33 |
|
| 34 |
Supported input types is integer of 32 bit and 64 bit size. |
| 35 |
|
| 36 |
``` |
| 37 |
interface btest |
| 38 |
module procedure btest32, btest64 |
| 39 |
end interface |
| 40 |
|
| 41 |
contains |
| 42 |
|
| 43 |
interface |
| 44 |
elemental logical function btest32(x, pos) |
| 45 |
integer(int32), intent(in) :: x |
| 46 |
integer, intent(in) :: pos |
| 47 |
end function |
| 48 |
|
| 49 |
elemental logical function btest64(x, pos) |
| 50 |
integer(int64), intent(in) :: x |
| 51 |
integer, intent(in) :: pos |
| 52 |
end function |
| 53 |
end interface |
| 54 |
``` |
| 55 |
|
| 56 |
## Examples |
| 57 |
|
| 58 |
```fortran |
| 59 |
program intrinsics_btest |
| 60 |
implicit none |
| 61 |
print *, btest(2, 0) |
| 62 |
end program |
| 63 |
``` |
| 64 |
|
| 65 |
**Result:** |
| 66 |
|
| 67 |
``` |
| 68 |
false |
| 69 |
``` |
| 70 |
|
| 71 |
## See Also |