<?Php
echo dechex(2); // Output 2
echo "<br>";
echo dechex(25); // Output 19
echo "<br>";
echo dechex(200); // Output is c8
echo "<br>";
echo dechex(358); // Output is 166
echo "<br>";
echo dechex(2000); // Output is 7d0
?>
Syntax
string dechex(int $number);
| Parameter | DESCRIPTION |
|---|---|
| $number | Required : Decimal number as Input to convert to equivalent hexadecimal number. |
<?php
echo dechex(10000); // Output: 2710
?>
<?php
echo dechex(-255); // Output: ffffff01 (two's complement representation)
?>
<?php
$numbers = [15, 255, 4096];
foreach ($numbers as $num) {
echo dechex($num) . "<br>";
}
?>
<?php
$number = 255;
echo str_pad(dechex($number), 4, '0', STR_PAD_LEFT); // Output: 00ff
?>
<?php
for ($i = 0; $i <= 10; $i++) {
echo "Decimal: $i => Hex: " . dechex($i) . "<br>";
}
?>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.