Manual Reference Pages  - bit_size (3fortran)

NAME

BIT_SIZE(3) - [BIT:INQUIRY] Bit size inquiry function

SYNOPSIS

result = bit_size(i)

         integer(kind=KIND) function bit_size(i)

integer(kind=KIND),intent(in) :: i(..)

CHARACTERISTICS

o I shall be of type integer. It may be a scalar or an array.
o the value of KIND is any valid value for an integer kind parameter on the processor.
o the return value is a scalar of the same kind as the input value.

DESCRIPTION

BIT_SIZE(3) returns the number of bits (integer precision plus sign bit) represented by the type of the integer I.

OPTIONS

o I : An integer value of any kind whose size in bits is to be determined. Because only the type of the argument is examined, the argument need not be defined; I can be a scalar or an array, but a scalar representing just a single element is always returned.

RESULT

The number of bits used to represent a value of the type and kind of i. The result is a integer scalar of the same kind as i.

EXAMPLES

Sample program:

    program demo_bit_size
    use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64
    use,intrinsic :: iso_fortran_env, only : integer_kinds
    implicit none
    character(len=*),parameter   :: fmt=&
    & ’(a,": bit size is ",i3," which is kind=",i3," on this platform")’

! default integer bit size on this platform write(*,fmt) "default", bit_size(0), kind(0)

write(*,fmt) "int8 ", bit_size(0_int8), kind(0_int8) write(*,fmt) "int16 ", bit_size(0_int16), kind(0_int16) write(*,fmt) "int32 ", bit_size(0_int32), kind(0_int32) write(*,fmt) "int64 ", bit_size(0_int64), kind(0_int64)

write(*,’(a,*(i0:,", "))’) "The available kinds are ",integer_kinds

end program demo_bit_size

Typical Results:

        default: bit size is  32 which is kind=  4 on this platform
        int8   : bit size is   8 which is kind=  1 on this platform
        int16  : bit size is  16 which is kind=  2 on this platform
        int32  : bit size is  32 which is kind=  4 on this platform
        int64  : bit size is  64 which is kind=  8 on this platform
        The available kinds are 1, 2, 4, 8, 16

STANDARD

Fortran 95

SEE ALSO

****(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 bit_size (3fortran) April 28, 2024
Generated by manServer 1.08 from 23045426-4bf4-4051-ac80-cfb9d1decb53 using man macros.