PHP | dechex( ) Function

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:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo dechex(10);
      
    ?>    

    chevron_right

    
    

    Output:

    a
  • Passing 47 as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo dechex(47);
      
    ?>      

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <?php
      
    echo dechex(4294967295);
      
    ?>      

    chevron_right

    
    

    Output:

    ffffffff

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



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.