PHP hexdec() Function

Definition and Usage

The hexdec() function converts hexadecimal to decimal.

Syntax

hexdec(hex_string)
Parameter Description
hex_string Required. Specifies the hexadecimal number to be converted.

Description

Returns with hex_string The decimal number equivalent to the hexadecimal number represented by the parameter. hexdec() converts a hexadecimal string to a decimal number. The maximum value that can be converted is 7fffffff, which is 2147483647 in decimal. Starting from PHP 4.1.0, this function can handle large numbers, in which case it will return a float type.

hexdec() will replace all non-hexadecimal characters with 0. In this way, all leading zeros are ignored, but the trailing zeros are counted in the value.

Example

<?php
echo hexdec("1e");
echo hexdec("a");
echo hexdec("11ff");
echo hexdec("cceeff");
?>

Output:

30
10
4607
13430527