Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_setbit

Description

The gmp_setbit of GMP for PHP sets a bit.

Syntax

gmp_setbit(
    GMP $num,
    int $index,
    bool $value = true
): void

Parameters

num

A GMP object.

index

The index of the bit to set. Index 0 represents the least significant bit.

value

True to set the bit to 1 (on); false to clear/set the bit to 0 (off).

Return

No value is returned.

Examples

1 · num index · 0

<?

$num = 0b100;
$index = 0;

$num = gmp_init($num);

gmp_setbit($num, $index);

$base = 2;

$gmp_strval = gmp_strval($num, $base);

echo $gmp_strval;

?>
101

2 · num index · 1

<?

$num = 0b100;
$index = 1;

$num = gmp_init($num);

gmp_setbit($num, $index);

$base = 2;

$gmp_strval = gmp_strval($num, $base);

echo $gmp_strval;

?>
110

3 · value · false

<?

$num = 0b101;
$index = 0;
$value = false;

$num = gmp_init($num);

gmp_setbit($num, $index, $value);

$base = 2;

$gmp_strval = gmp_strval($num, $base);

echo $gmp_strval;

?>
100

4 · value · true

<?

$num = 0b100;
$index = 0;
$value = true;

$num = gmp_init($num);

gmp_setbit($num, $index, $value);

$base = 2;

$gmp_strval = gmp_strval($num, $base);

echo $gmp_strval;

?>
101
HomeMenu