Definition and usage
The base_convert () function converts numbers in any hexadecimal format.
Syntax
Base_convert (number, frombase, tobase)
Parameters |
Description |
Number |
Required. Original Value. |
Frombase |
Required. The original hexadecimal number. |
Tobase |
Required. The hexadecimal format to be converted. |
Description
Returns a string containingNumber
ToTobase
Hexadecimal representation.Number
The hexadecimal StructureFrombase
.Frombase
AndTobase
It can only be between 2 and 36 (including 2 and 36 ). Numbers higher than decimal digits are represented by the letter A-Z. For example, a represents 10, B represents 11, and Z represents 35.
Example 1
Convert octal to decimal:
<? PHP
$ Oct = "0031 ";
$ Dec = base_convert ($ Oct, 8, 10 );
$ Oct of Echo "is equal to $ dec in decimal format. ";
?>
Output:
0031 Of The octal value is equal to 25 in decimal format.
Example 2
Convert the octal number to the hexadecimal number:
<? PHP
$ Oct = "364 ";
$ Hex = base_convert ($ Oct, 8, 16 );
$ Oct of Echo "is equal to $ hex in hexadecimal format. ";
?>
Output:
364 of octal is equal to F4.