PHP dechex

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $val1= 120;  

  2. $val2=7;  

  3. $val3=9899;  

  4. $zhexa1=dechex($val1);  

  5. $zhexa2=dechex($val2);  

  6. $zhexa3=dechex($val3);  

  7. echo "Hexa value of $val1 is $zhexa1
    ";  

  8. echo "Hexa value of $val2 is $zhexa2
    ";  

  9. echo "Hexa value of $val3 is $zhexa3
    ";  

  10. ?>  

Output :

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