PHP Function Reference

PHP hexdec() Function



The PHP hexdec() function returns the decimal number equivalent to the hexadecimal number represented by the hexadecimal string argument.

The table below shows hexadecimal numbers converted into decimal numbers.

HexadecimalDecimalHexadecimalDecimal
11a10
22b11
33c12
44d13
55e14
66f15
771016
881f31
99ff255

Syntax

hexdec(hex_string)

Parameters

hex_string Required. Specify the hexadecimal number to convert.

Return Value

The decimal representation of a hexadecimal string argument.

Example:

In the example below, hexdec() function returns the decimal representation of a hexadecimal string argument.

<?php
echo "hexdec(0) = ".hexdec(0)."\n";
echo "hexdec(1) = ".hexdec(1)."\n";
echo "hexdec(10) = ".hexdec(10)."\n";
echo "hexdec('fff') = ".hexdec('fff')."\n";
echo "hexdec('1ff') = ".hexdec('1ff')."\n";
echo "hexdec('eff') = ".hexdec('eff')."\n";
echo "hexdec('100f') = ".hexdec('100f')."\n";
echo "hexdec('54e21') = ".hexdec('54e21')."\n";
?>

The output of the above code will be:

hexdec(0) = 0
hexdec(1) = 1
hexdec(10) = 16
hexdec('fff') = 4095
hexdec('1ff') = 511
hexdec('eff') = 3839
hexdec('100f') = 4111
hexdec('54e21') = 347681

❮ PHP Math Reference