w3resource

PHP: dechex() function

Description

The dechex() function is used to convert a decimal number to a hexadecimal number.

Version:

(PHP 4 and above)

Syntax:

dechex(num)

Parameter:

Name Description Required /
Optional
Type
num The decimal number to convert.  Required Integer

Return value:

Hexadecimal string representation of num.

Value Type: String.

Pictorial Presentation

php-math-dechex()

Example:


<?php
$val1= 120;
$val2=7;
$val3=9899;
$zhexa1=dechex($val1);
$zhexa2=dechex($val2);
$zhexa3=dechex($val3);
echo "Hexa value of $val1 is $zhexa1<br />";
echo "Hexa value of $val2 is $zhexa2<br />";
echo "Hexa value of $val3 is $zhexa3<br />";
?>

Output:

Hexa value of 120 is 78
Hexa value of 7 is 7
Hexa value of 9899 is   26ab

View the example the browser

See also

PHP Function Reference

Previous: decbin
Next: decoct



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/php/function-reference/dechex.php