The hexdec
method can be used to convert a hexadecimal
string to a decimal
number.
hexdec(string $hex_string): int|float
Any invalid characters in the hex_string
argument are skipped.
From PHP 7.4.0, any invalid character in
hex_string
is deprecated.
It returns the decimal number of type int
or float
based on the size of the value.
<?php$num = "a";echo "HexaDecimal value of ". $num. " is: ". hexdec($num)."\n";$num = "b";echo "HexaDecimal value of ". $num. " is: ". hexdec($num)."\n";$num = "c";echo "HexaDecimal value of ". $num. " is: ". hexdec($num)."\n";$num = "f";echo "HexaDecimal value of ". $num. " is: ". hexdec($num)."\n";?>
In the code above, we used the hexdec
method to convert the hexadecimal values of a
, b
, c
and f
into decimal numbers.