hexdec()

Published Jul 12, 2023
Contribute to Docs

The hexdec() function returns the decimal equivalent of a given hexadecimal string. It ignores any non-hexadecimal characters, computing the result as if they did not exist.

The function returns a value of type int if the converted number fits into the platform’s int type; otherwise, a float is returned.

Syntax

$decimal = hexdec(hexString);

Where hexString is the hexadecimal string that is to be converted into a decimal.

Example

This example converts the hexadecimal string "CDECADE" into its decimal equivalent.

<?php
$decimal = hexdec("CDECADE");
echo $decimal;
?>

This example results in the following output:

215927518

Codebyte Example

This example returns the value of both a well-formed hexadecimal string and its malformed equivalent (non-hexadecimal characters ignored):

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy