dechex

(PHP 4, PHP 5, PHP 7, PHP 8)

dechex十進制轉(zhuǎn)換為十六進制

說明

dechex(int $number): string

返回一字符串,包含有給定 number 參數(shù)的十六進制表示。

所能轉(zhuǎn)換的最大數(shù)值為十進制的 PHP_INT_MAX * 2 + 1 (或 -1):在 32 位平臺上是十進制的 4294967295,其 dechex() 的結(jié)果為 ffffffff。

參數(shù)

number

要轉(zhuǎn)換的十進制值

PHP 的 integer 類型是有符號的,但 dechex() 處理無符號整數(shù),負正數(shù)會以無符號處理。

返回值

number 的16進制表示

范例

示例 #1 dechex() 例子

<?php
echo dechex(10) . "\n";
echo 
dechex(47);
?>

以上例程會輸出:

a
2f

示例 #2 大整數(shù)的 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 1)."\n";
echo 
dechex(pow(232) - 1)."\n";
?>

以上例程會輸出:

ffffffff
ffffffff
ffffffff

參見

  • hexdec() - 十六進制轉(zhuǎn)換為十進制
  • decbin() - 十進制轉(zhuǎn)換為二進制
  • decoct() - 十進制轉(zhuǎn)換為八進制
  • base_convert() - 在任意進制之間轉(zhuǎn)換數(shù)字