<?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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.