| 1 |
# bit_size(x): Bit Size |
| 2 |
|
| 3 |
Bit size. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = bit_size(x); |
| 11 |
elemental logical function bit_size(x) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` is integer input value. |
| 17 |
|
| 18 |
### Return values |
| 19 |
|
| 20 |
The return value is of type integer. |
| 21 |
|
| 22 |
## Description |
| 23 |
|
| 24 |
`bit_size(x)` calculates the number of bits including sign bit of binary |
| 25 |
representation of `x`. |
| 26 |
|
| 27 |
## Types |
| 28 |
|
| 29 |
Supported input types is integer. |
| 30 |
|
| 31 |
``` |
| 32 |
module lfortran_intrinsic_builtin |
| 33 |
implicit none |
| 34 |
|
| 35 |
contains |
| 36 |
|
| 37 |
interface |
| 38 |
integer function bit_size(x) |
| 39 |
integer, intent(in) :: x |
| 40 |
end function |
| 41 |
end interface |
| 42 |
``` |
| 43 |
|
| 44 |
## Examples |
| 45 |
|
| 46 |
```fortran |
| 47 |
program intrinsics_bit_size |
| 48 |
implicit none |
| 49 |
print *, bit_size(123) |
| 50 |
print *, bit_size(-1) |
| 51 |
end program |
| 52 |
``` |
| 53 |
|
| 54 |
**Result:** |
| 55 |
|
| 56 |
``` |
| 57 |
32 |
| 58 |
32 |
| 59 |
``` |
| 60 |
|
| 61 |
## See Also |
| 62 |
|