How to Convert Hexadecimal to Decimal Using PHP?

In PHP, it is easy to convert Hexadecimal to Decimal. PHP provides hexdec() function which returns the decimal equivalent of the hexadecimal number represented by the hex_string argument.

echo hexdec("ab");
// 171

This method will ignore any non-hexadecimal characters in the provided string.

echo hexdec("abs");
// 171. It skips "s" in the string.

hexdec() converts numbers to integer type. If the number is too large to fit in integer type, it is converted to float one.

echo hexdec("AAA3453AADBBCCFFEE");

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.