PHP base_convert()Functions
Examples
Convert hexadecimal number to octal number:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
$hex = "E196";
echo base_convert($hex,16,8);
?>
Run example »
Definition and Usage
The base_convert() function converts a number between arbitrary bases.
Syntax
base_convert(number,frombase,tobase);
| Parameters | Description |
|---|---|
| number | Required. Specifies the number to convert. |
| frombase | Required. Specifies the original base of the number. Between 2 and 36 (inclusive). Numbers higher than decimal are represented by letters a-z, for example a represents 10, b represents 11, and z represents 35. |
| tobase | Required. Specifies the base to convert to. Between 2 and 36 (inclusive). Numbers higher than decimal are represented by letters a-z, for example a represents 10, b represents 11, and z represents 35. |
Technical Details
| Return value: | numberConverted to the specified base. |
|---|---|
| Return type: | String |
| PHP Version: | 4+ |
More Examples
Example 1
Convert octal number to decimal number:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
$oct = "0031";
echo base_convert($oct,8,10);
?>
Run example »
Example 2
Convert octal number to hexadecimal number:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
$oct = "364";
echo base_convert($oct,8,16);
?>
Run example »
PHP Math Reference Manual Other Extensions