hexdec():decimal equivalent of hexadeciam number

Convert hexadecimal to decimal

hexdec() converts a hexadecimal string to its decimal value.

$hex = '2f';
echo hexdec($hex); // 47

Start with this current pattern. The examples below are retained for additional variations, output and reference.

<?Php
echo hexdec('2e'); // Output 46 
echo "<br>";
echo hexdec('2ch'); // Output 44 
echo "<br>";
echo hexdec('fab'); // Output is 4011
echo "<br>";
echo hexdec('FFFFFF'); // Output is 16777215
?>
Syntax
string hexdec(string $hex);
ParameterDESCRIPTION
$hexRequired : $hex string to convert to equivalent decimal number.
The output is decimal number.
Hexadecimal is positional numeral system with base of 16. The chars it used are from 0 to 9 and from A to F.

Before using hexdec() to convert hexadecimal to decimal system, we can check hexadecimal input string for a valid hexadecimal number or not by using ctype_xdigit.php function.

Here is Demo of checking and converting Hexadecimal input to decimal base number.

DEMO




Example: Converting Hex Color Codes to Decimal

$hex = "FF";
echo hexdec($hex);  // Output: 255

Example: Handling Large Hexadecimal Values

$hex = "7FFFFFFF";
echo hexdec($hex);  // Output: 2147483647

Math Functions dechex(): Convert decimal number to hexadecimal system
base_convert(): Convert number From any base to other decbin() Binary equivalent of decimal number


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer