gmp_setbit
is a PHP function that sets the bit’s index in the first parameter passed to the function.
gmp_setbit(GMP $num, int $index, bool $value = true): void
num
: The value that needs to be modified.
num
can be a numeric string, GMP object, or of the integer type.
index
: The bit’s index needed to be set.Here, if the index equals zero, it means that the index represents the least significant bit.
value
: A value of the Boolean type. The value is kept True
if we need to the bet. Otherwise, it returns False
.The function returns a GMP number.
<?php// gmp_init creates a gmp number$number = gmp_init("2");echo gmp_strval($number), ' -> 0b', gmp_strval($number, 2), "\n";gmp_setbit($number, 0);?>
2 -> 0b10