PHP dechex() Function
The PHP dechex() function returns a string which is the hexadecimal representation of a decimal number.
The table below shows decimal numbers converted into hexadecimal numbers.
Decimal | Hexadecimal | Decimal | Hexadecimal |
---|---|---|---|
1 | 1 | 10 | a |
2 | 2 | 11 | b |
3 | 3 | 12 | c |
4 | 4 | 13 | d |
5 | 5 | 14 | e |
6 | 6 | 15 | f |
7 | 7 | 16 | 10 |
8 | 8 | 31 | 1f |
9 | 9 | 255 | ff |
Syntax
dechex(number)
Parameters
number |
Required. Specify the decimal number to convert. |
Return Value
Hexadecimal string representation of a decimal number.
Example:
In the example below, dechex() function returns the hexadecimal string representation of a given decimal number.
<?php echo "dechex(0) = ".dechex(0)."\n"; echo "dechex(1) = ".dechex(1)."\n"; echo "dechex(15) = ".dechex(15)."\n"; echo "dechex(50) = ".dechex(50)."\n"; echo "dechex(100) = ".dechex(100)."\n"; echo "dechex(500) = ".dechex(500)."\n"; echo "dechex('1000') = ".dechex('1000')."\n"; echo "dechex('54321') = ".dechex('54321')."\n"; ?>
The output of the above code will be:
dechex(0) = 0 dechex(1) = 1 dechex(15) = f dechex(50) = 32 dechex(100) = 64 dechex(500) = 1f4 dechex('1000') = 3e8 dechex('54321') = d431
❮ PHP Math Reference