Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<gmp_divexactgmp_fact>
^GMP FunctionsLast updated: Mon, 26 Oct 2026

gmp_export

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

gmp_export — Export to a binary string

Description

function gmp_export(GMP|int|string $num, int $word_size = 1, int $flags = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string

Exports a GMP number to a binary string. This function can handle arbitrarily large numbers beyond the range of PHP's native integer type, with configurable word size and byte order, similar in spirit to pack().

The sign of the number is ignored; exporting a negative number produces the same result as exporting its absolute value.

Parameters

num

The GMP number to export.

word_size

The number of bytes per word in the output. The total length of the returned string will be a multiple of this value. Default value: 1.

flags

A bitmask controlling word order and byte order. Word order: GMP_MSW_FIRST (most significant word first, default) or GMP_LSW_FIRST (least significant word first). Byte order within each word: GMP_NATIVE_ENDIAN (default), GMP_BIG_ENDIAN, or GMP_LITTLE_ENDIAN. Default value: GMP_MSW_FIRST | GMP_NATIVE_ENDIAN.

Return Values

Returns a string containing the binary representation of the GMP number. The string is empty if the number is zero.

Changelog

Version Description
8.0.0 This function no longer returns false on failure.

Examples

Example #1 gmp_export() example

<?php
$number = gmp_init(16705);
echo gmp_export($number) . "\n";
?>

The above example will output:

AA

See Also


<gmp_divexactgmp_fact>
^GMP FunctionsLast updated: Mon, 26 Oct 2026