PHP base_convert () function
Examples
The hexadecimal number to octal numbers:
<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
$hex = "E196";
echo base_convert($hex,16,8);
?>
Running instance »
Definition and Usage
base_convert () function to convert between any hexadecimal digit.
grammar
base_convert( number,frombase,tobase );
参数 | 描述 |
---|---|
number | 必需。规定要转换的数。 |
frombase | 必需。规定数字原来的进制。介于 2 和 36 之间(包括 2 和 36)。高于十进制的数字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。 |
tobase | 必需。规定要转换的进制。介于 2 和 36 之间(包括 2 和 36)。高于十进制的数字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。 |
technical details
return value: | converted to the specified decimal number. |
---|---|
Return type: | String |
PHP version: | 4+ |
More examples
Example 1
The octal number to decimal number:
<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
$oct = "0031";
echo base_convert($oct,8,10);
?>
Running instance »
Example 2
The octal number to hexadecimal number:
<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
$oct = "364";
echo base_convert($oct,8,16);
?>
Running instance »
PHP Math Reference