Home >>PHP Math Functions >PHP dechex() Function

PHP dechex() Function

PHP dechex() Function

PHP dechex() function is used to convert a given input decimal number to an equivalent hexadecimal number. It works only with the unsigned numbers and If the argument passed to it is a negative number then it will treat that number as an unsigned number. It accepts only a single parameter $number which is the decimal number to be converted in hexadecimal representation. It returns the hexadecimal string representation of the given number as output.

Syntax:

  dechex($number);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the decimal value to convert.

Here is an example of dechex() function in PHP:

<html>
<body>

<?php

echo dechex("5") . "<br>";
echo dechex("15") . "<br>";

?>

</body>
</html>
Output:
5
f

Here is an another example of dechex() function in PHP:

<html>
<body>

<?php

echo dechex("51") . "<br>";
echo dechex("77") . "<br>";
echo dechex("563") . "<br>";
echo dechex("27") . "<br>";
echo dechex("2") . "<br>";

?>

</body>
</html>
Output:
33
4d
233
1b
2

No Sidebar ads