PHP hexdec() Function
The PHP hexdec() function returns the decimal number equivalent to the hexadecimal number represented by the hexadecimal string argument.
The table below shows hexadecimal numbers converted into decimal numbers.
Hexadecimal | Decimal | Hexadecimal | Decimal |
---|---|---|---|
1 | 1 | a | 10 |
2 | 2 | b | 11 |
3 | 3 | c | 12 |
4 | 4 | d | 13 |
5 | 5 | e | 14 |
6 | 6 | f | 15 |
7 | 7 | 10 | 16 |
8 | 8 | 1f | 31 |
9 | 9 | ff | 255 |
Syntax
hexdec(hex_string)
Parameters
hex_string |
Required. Specify the hexadecimal number to convert. |
Return Value
The decimal representation of a hexadecimal string argument.
Example:
In the example below, hexdec() function returns the decimal representation of a hexadecimal string argument.
<?php echo "hexdec(0) = ".hexdec(0)."\n"; echo "hexdec(1) = ".hexdec(1)."\n"; echo "hexdec(10) = ".hexdec(10)."\n"; echo "hexdec('fff') = ".hexdec('fff')."\n"; echo "hexdec('1ff') = ".hexdec('1ff')."\n"; echo "hexdec('eff') = ".hexdec('eff')."\n"; echo "hexdec('100f') = ".hexdec('100f')."\n"; echo "hexdec('54e21') = ".hexdec('54e21')."\n"; ?>
The output of the above code will be:
hexdec(0) = 0 hexdec(1) = 1 hexdec(10) = 16 hexdec('fff') = 4095 hexdec('1ff') = 511 hexdec('eff') = 3839 hexdec('100f') = 4111 hexdec('54e21') = 347681
❮ PHP Math Reference