array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.dechex.php', 1 => 'dechex', ), 'up' => array ( 0 => 'ref.math.php', 1 => 'Math 函数', ), 'prev' => array ( 0 => 'function.decbin.php', 1 => 'decbin', ), 'next' => array ( 0 => 'function.decoct.php', 1 => 'decoct', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/math/functions/dechex.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
dechex — 十进制转换为十六进制
返回一字符串,包含有给定
num
参数的十六进制表示。
所能转换的最大数值为十进制的
PHP_INT_MAX
* 2 + 1
(或
-1
):在 32 位平台上是十进制的 4294967295
,其 dechex() 的结果为 ffffffff
。
num
的16进制表示
示例 #1 dechex() 示例
<?php
echo dechex(10) . "\n";
echo dechex(47);
?>
以上示例会输出:
a 2f
示例 #2 大整数的 dechex() 示例
<?php
// 下面的输出假设是 32 位平台。
// 注意输出的所有值一样。
echo dechex(-1)."\n";
echo dechex(PHP_INT_MAX * 2 + 1)."\n";
echo dechex(pow(2, 32) - 1)."\n";
?>
以上示例会输出:
ffffffff ffffffff ffffffff