PHP dechex()函数
dechex() 是预定义的PHP数学函数,用于将十进制数转换为十六进制数。
语法
string dechex ( int $number );
参数 | 描述 | 必需/可选 |
---|---|---|
number | 指定十进制值 | 必需 |
示例1
<?php
decimal=7;
echo "Your Decimal number is : ".decimal."<br>";
echo "By using 'dechex()'function, your Hexadecimal number is :".dechex($decimal);
?>
输出:
Your Decimal number is : 7
By using 'dechex()'function, your Hexadecimal number is :7
示例2
<?php
decimal=10;
echo "Your Decimal number is : ".decimal."<br>";
echo "By using 'dechex()'function, your Hexadecimal number is :".dechex($decimal);
?>
输出:
Your Decimal number is : 10
By using 'dechex()'function, your Hexadecimal number is :a
示例3
<?php
decimal=30;
echo "Your Decimal number is : ".decimal."<br>";
echo "By using 'dechex()'function, your Hexadecimal number is :".dechex($decimal);
?>
输出:
Your Decimal number is : 30
By using 'dechex()'function, your Hexadecimal number is :1e
示例4
<?php
decimal=1587;
echo "Your Decimal number is : ".decimal."<br>";
echo "By using 'dechex()'function, your Hexadecimal number is :".dechex($decimal);
?>
输出:
Your Decimal number is : 1587
By using 'dechex()'function, your Hexadecimal number is :633
示例5
<?php
decimal=70;
echo "Your Decimal number is : ".decimal."<br>";
echo "By using 'dechex()'function, your Hexadecimal number is :".dechex($decimal);
?>
输出:
Your Decimal number is : 70
By using 'dechex()'function, your Hexadecimal number is :46
示例6
<?php
// The output below assumes a 32-bit platform.
// Note that the output is the same for all values.
echo dechex(-1)."\n";
echo dech ex(PHP_INT_MAX * 2 + 1)."\n";
echo dechex(pow(2, 32) - 1)."\n";
?>
输出:
ffffffff
ffffffff
ffffffff