(PHP 4, PHP 5, PHP 7, PHP 8)
dechex — 十進(jìn)制轉換為十六進(jìn)制
$number
): string
返回一字符串,包含有給定
number
參數的十六進(jìn)制表示。
所能轉換的最大數值為十進(jìn)制的
PHP_INT_MAX
* 2 + 1
(或
-1
):在 32 位平臺上是十進(jìn)制的 4294967295
,其 dechex() 的結果為 ffffffff
。
number
要轉換的十進(jìn)制值
PHP 的 integer 類(lèi)型是有符號的,但 dechex() 處理無(wú)符號整數,負正數會(huì )以無(wú)符號處理。
number
的16進(jìn)制表示
示例 #1 dechex() 例子
<?php
echo dechex(10) . "\n";
echo dechex(47);
?>
以上例程會(huì )輸出:
a 2f
示例 #2 大整數的 dechex() 例子
<?php
// The output below assumes a 32-bit platform.
// Note that the output is the same for all values.
echo dechex(-1)."\n";
echo dechex(PHP_INT_MAX * 2 + 1)."\n";
echo dechex(pow(2, 32) - 1)."\n";
?>
以上例程會(huì )輸出:
ffffffff ffffffff ffffffff