导航首页 » 技术教程 » PHP:dechex()的用法_Math函数
PHP:dechex()的用法_Math函数 133 2024-01-01   

dechex

(PHP 4, PHP 5)

dechex — 十进制转换为十六进制

说明

string dechex ( int $number )

返回一字符串,包含有给定 number 参数的十六进制表示。

所能转换的最大数值为十进制的 PHP_INT_MAX * 2 + 1 (或 -1):在 32 位平台上是十进制的 4294967295,其 dechex() 的结果为 ffffffff。

参数

number

要转换的十进制值

PHP 的 integer 类型是有符号的,但 dechex() 处理无符号整数,负正数会以无符号处理。

返回值

number 的16进制表示

范例

Example #1 dechex() 例子

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

以上例程会输出:

a
2f

Example #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";
?>

以上例程会输出:

ffffffff
ffffffff
ffffffff

参见

hexdec() - 十六进制转换为十进制 decbin() - 十进制转换为二进制 decoct() - 十进制转换为八进制 base_convert() - 在任意进制之间转换数字



!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103