GMP_INIT(3) 1 GMP_INIT(3)gmp_init - Create GMP numberSYNOPSIS
GMP gmp_init (mixed $number, [int $base])
DESCRIPTION
Creates a GMP number from an integer or string.
PARAMETERS
o $number
- An integer or a string. The string representation can be decimal, hexadecimal or octal.
o $base
- The base. The base may vary from 2 to 36. If base is 0 (default value), the actual base is determined from the leading charac-
ters: if the first two characters are 0x or 0X, hexadecimal is assumed, otherwise if the first character is "0", octal is assumed,
otherwise decimal is assumed.
RETURN VALUES
A GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.3.2 | |
| | |
| | The $base was extended from 2 to 36, to 2 to 62 |
| | and -2 to -36. |
| | |
+--------+---------------------------------------------------+
NOTES
Note
To use the extended base introduced in PHP 5.3.2, then PHP must be compiled against GMP 4.2.0 or greater.
EXAMPLES
Example #1
Creating GMP number
<?php
$a = gmp_init(123456);
$b = gmp_init("0xFFFFDEBACDFEDF7200");
?>
NOTES
Note
It is not necessary to call this function if you want to use integer or string in place of GMP number in GMP functions, like
gmp_add(3). Function arguments are automatically converted to GMP numbers, if such conversion is possible and needed, using the same
rules as gmp_init(3).
PHP Documentation Group GMP_INIT(3)
Check Out this Related Man Page
GMP_SETBIT(3) 1 GMP_SETBIT(3)gmp_setbit - Set bitSYNOPSIS
void gmp_setbit (GMP &$a, int $index, [bool $bit_on = true])
DESCRIPTION
Sets bit $index in $a.
PARAMETERS
o $a
- The value to modify. Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string
provided that it is possible to convert the latter to a number.
o $index
- The index of the bit to set. Index 0 represents the least significant bit.
o $bit_on
- True to set the bit (set it to 1/on); false to clear the bit (set it to 0/off).
RETURN VALUES
A GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later.
EXAMPLES
Example #1
gmp_setbit(3) example - 0 index
<?php
$a = gmp_init("2"); //
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 0); // 0b10 now becomes 0b11
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
2 -> 0b10
3 -> 0b11
Example #2
gmp_setbit(3) example - 1 index
<?php
$a = gmp_init("0xfd");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 1); // index starts at 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
253 -> 0b11111101
255 -> 0b11111111
Example #3
gmp_setbit(3) example - clearing a bit
<?php
$a = gmp_init("0xff");
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
gmp_setbit($a, 0, false); // clear bit at index 0
echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "
";
?>
The above example will output:
255 -> 0b11111111
254 -> 0b11111110
NOTES
Note
Unlike most of the other GMP functions, gmp_setbit(3) must be called with a GMP resource that already exists (using gmp_init(3) for
example). One will not be automatically created.
SEE ALSO gmp_clrbit(3), gmp_testbit(3).
PHP Documentation Group GMP_SETBIT(3)