IBSET(3) - [BIT:SET] Set a bit to one in an integer value
result = ibset(i, pos)
elemental integer(kind=KIND) function ibset(i,pos)integer(kind=KIND),intent(in) :: i integer(kind=**),intent(in) :: pos
o a kind designated as ** may be any supported kind for the type o The return value is of the same kind as I. Otherwise, any integer kinds are allowed.
IBSET(3) returns the value of I with the bit at position POS set to one.
o I : The initial value to be modified o POS : The position of the bit to change in the input value. A value of zero refers to the right-most bit. The value of POS must be nonnegative and less than (BIT_SIZE(I)).
The returned value has the same bit sequence as I except the designated bit is unconditionally set to 1.
Sample program:
program demo_ibset use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 implicit none integer(kind=int16) :: i ! basic usage print *,ibset (12, 1), ibset(12,1) has the value 14Results:! it is easier to see using binary representation i=int(b0000000000000110,kind=int16) write(*,(b16.16,1x,i0,1x,i0)) ibset(i,12), ibset(i,12), i
! elemental print *,an array of initial values may be given as well print *,ibset(i=[0,4096], pos=2) print * print *,a list of positions results in multiple returned values print *,not multiple bits set in one value, as the routine is print *,a scalar function; calling it elementally essentially print *,calls it multiple times. write(*,(b16.16)) ibset(i=0, pos=[1,2,3,4])
! both may be arrays if of the same size
end program demo_ibset
> 14 ibset(12,1) has the value 14 > 0001000000000110 4102 6 > an array of initial values may be given as well > 4 4100 > > a list of positions results in multiple returned values > not multiple bits set in one value, as the routine is > a scalar function; calling it elementally essentially > calls it multiple times. > 0000000000000010 > 0000000000000100 > 0000000000001000 > 0000000000010000
Fortran 95
IBCLR(3)
BTEST(3), IAND(3), IBITS(3), IEOR(3), IOR(3), MVBITS(3), NOT(3)
Fortran intrinsic descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | ibset (3fortran) | November 02, 2024 |