Open In App

PHP dechex( ) Function

Improve
Improve
Like Article
Like
Save
Share
Report

The dechex() is a built-in function in PHP and is used to convert a given decimal number to an equivalent hexadecimal number. The word ‘dechex’ in the name of function stands for decimal to hexadecimal. The dechex() function works only with unsigned numbers. If the argument passed to it is negative then it will treat it as an unsigned number.
The largest number that can be converted is 4294967295 in decimal resulting to “ffffffff”.

Syntax:

string dechex($value)

Parameters: This function accepts a single parameter $value. It is the decimal number you want to convert in hexadecimal representation.

Return Value: It returns the hexadecimal string representation of number passed to it as argument.

Examples:

Input : dechex(10)
Output : a

Input : dechex(47)
Output : 2f

Input : dechex(4294967295)
Output : ffffffff

Below programs illustrate dechex() function in PHP:

  • Passing 10 as a parameter:




    <?php
      
    echo dechex(10);
      
    ?>    

    
    

    Output:

    a
  • Passing 47 as a parameter:




    <?php
      
    echo dechex(47);
      
    ?>      

    
    

    Output:

    2f
  • When the largest possible decimal number is passed as a parameter:




    <?php
      
    echo dechex(4294967295);
      
    ?>      

    
    

    Output:

    ffffffff

Reference:
http://php.net/manual/en/function.dechex.php



Last Updated : 22 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads