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

gmp_init

Description

The gmp_init of GMP for PHP creates a GMP number.

Syntax

gmp_init(
    int|string $num,
    int $base = 0
): GMP

Parameters

num

An integer or a string. The string representation can be binary, octal, decimal, or hexadecimal.

base

The base.

If base is 0 (default), the actual base is determined from the leading characters: if the first two characters are 0b or 0B, binary is assumed; if the first two characters are 0o or 0O, octal is assumed; if the first character is 0, octal is assumed; if the first two characters are 0x or 0X, hexadecimal is assumed; otherwise decimal is assumed.

The base may vary from 2 to 62.

For bases up to 36, case is ignored; upper-case and lower-case letters have the same value.

For bases 37 to 62, upper-case letters represent 10 to 35 while lower-case letters represent 36 to 61.

Return

Returns a GMP object.

Examples

1 · num · int · binary

<?

$num = 0b01;

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

2 · num · int · octal

<?

$num = 0o01234567;

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(6) "342391"
}

3 · num · int · decimal

<?

$num = 1234567890;

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(10) "1234567890"
}

4 · num · int · hexadecimal

<?

$num = 0x0123456789abcdef;

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(17) "81985529216486895"
}

5 · num · string · binary

<?

$num = "0b01";

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

6 · num · string · octal

<?

$num = "0o01234567";

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(6) "342391"
}

7 · num · string · decimal

<?

$num = "1234567890";

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(10) "1234567890"
}

8 · num · string · hexadecimal

<?

$num = "0x0123456789abcdef";

$return = gmp_init($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(17) "81985529216486895"
}

9 · base · 0 · binary

<?

$num = 0b01;
$base = 0;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

10 · base · 0 · octal

<?

$num = 0o01234567;
$base = 0;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(6) "342391"
}

11 · base · 0 · decimal

<?

$num = 1234567890;
$base = 0;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(10) "1234567890"
}

12 · base · 0 · hexadecimal

<?

$num = 0x0123456789abcdef;
$base = 0;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(17) "81985529216486895"
}

13 · base · 2 · binary

<?

$num = "01";
$base = 2;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

14 · base · 8 · octal

<?

$num = "01234567";
$base = 8;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(6) "342391"
}

15 · base · 10 · decimal

<?

$num = "0123456789";
$base = 10;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(9) "123456789"
}

16 · base · 16 · hexadecimal

<?

$num = "0123456789abcdef";
$base = 16;

$return = gmp_init($num, $base);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(17) "81985529216486895"
}
HomeMenu