当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP dechex()用法及代码示例


dechex() 是预定义的 PHP 数学函数,用于将十进制数转换为十六进制数。

用法:

string dechex ( int $number );
参数 描述 必需/可选
number 指定十进制值 Required

例子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






相关用法


注:本文由纯净天空筛选整理自 PHP dechex() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。