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");
//3.1477113666501E+21

Leave a Comment

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

We care about your privacy and data security. Google serves cookies to analyse traffic and show ads on this site. By using this site you agree to these cookies being set. 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.

Close