PHP Tutorial - PHP hexdec() Function






Definition

The hexdec() function converts a hexadecimal number to a decimal number.

To convert decimal to hexadecimal, use dechex() function.

Syntax

PHP hexdec() Function has the following syntax.

hexdec(hex_string);

Parameter

ParameterIs RequiredDescription
hex_stringRequired. Specifies the hexadecimal string to convert

Return

ItemDesscription
Return Value The decimal value of hex_string
Return Type Float / Integer




Example

Convert hexadecimal to decimal:


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

The code above generates the following result.