Home >Backend Development >PHP Problem >How to convert hexadecimal to decimal in php
In PHP, you can use the base_convert() function to convert the 17-base system to the 10-base system. This function can convert numbers between any base systems. You only need to specify the original base system and the base system to be converted. Just make it; the syntax is "base_convert("value to be converted",17,10)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use base_convert () function to convert hexadecimal to decimal.
Example: Convert hexadecimal "2003001" to decimal "48289878"
<?php $str="2003001"; $num=base_convert($str,17,10); echo $num; ?>
Output:
Description:
base_convert() function converts numbers between arbitrary bases.
Syntax:
base_convert(number,frombase,tobase);
Parameters | Description |
---|---|
number | Required. Specifies the number to be converted. |
frombase | Required. Specifies the original base of the number. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35. |
tobase | Required. Specifies the base to be converted. Between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35. |
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to convert hexadecimal to decimal in php. For more information, please follow other related articles on the PHP Chinese website!