當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。