HomeLanguagesPHP dechex( ) Function

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:




    <?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

RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS