大网数据广告活动
PHP 语言与运行手册

gmp_export · Export to a binary string

· 52CE 我爱测

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().

gmp_export

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

gmp_export — Export to a binary string

说明

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.

参数

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.

返回值

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

更新日志

版本 说明
8.0.0 This function no longer returns false on failure.

示例

示例 #1 gmp_export() example

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

以上示例会输出:

AA

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。