How to use hexdec() Function In PHP
The hexdec() function converts a hexadecimal number to a decimal number. This function converts numbers that are too large to fit into the integer type, larger values are returned as a float in that case. If hexdec() encounters any non-hexadecimal characters, it ignores them.
Syntax:
hexdec( $value )
Example:
PHP
<?php function hexToDec( $hex ) { return hexdec( $hex ); } $hexNum = '1A' ; $decimalNum = hexToDec( $hexNum ); echo "Decimal Value: " . $decimalNum ; ?> |
Decimal Value: 26
Hexadecimal to Decimal Conversion in PHP
Given a Hexadecimal Number, and the task is to convert Hexadecimal to a Decimal Number using PHP.
Examples:
Input: hexNum = '1A' Output: Input: hexNum = '634E24' Output: 6508068
There are three different methods to convert Hexadecimal to Decimal number, these are:
Table of Content
- Using hexdec() Function
- Using base_convert() Function
- Using for Loop