php8.5
Home/ Manual/ gmp / functions/ gmp_import

gmp_import

PHP function Edit on GitHub ✎

(PHP 5 >= 5.6.1, PHP 7, PHP 8)

Import from a binary string

Description

gmp_import(string $data, int $word_size = 1, int $flags = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): GMP

Import a GMP number from a binary string

Parameters

data

The binary string being imported

word_size

Default value is 1. The number of bytes in each chunk of binary data. This is mainly used in conjunction with the options parameter.

flags

Default value is GMP_MSW_FIRST | GMP_NATIVE_ENDIAN.

Return Values

Returns a GMP number.

Changelog

VersionDescription
8.0.0This function no longer returns false on failure.

Examples

gmp_import() example

php
<?php
$number = gmp_import("\0");
echo gmp_strval($number) . "\n";

$number = gmp_import("\0\1\2");
echo gmp_strval($number) . "\n";
?>

The above example will output:

output
0
258

See Also

Source: reference/gmp/functions/gmp-import.xml · from the official PHP manual (php/doc-en)