目录

PHP base_convert() 函数

❮ PHP 数学参考

示例

将十六进制数转换为八进制数:

<?php
$hex = "E196";
echo base_convert($hex,16,8);
?>
亲自试一试 »

定义和用法

base_convert() 函数将数字从一种数字基数转换为另一种数字基数。


语法

base_convert( number,frombase,tobase);

参数值

Parameter Description
number Required. Specifies the number to convert
frombase Required. Specifies the original base of number. Has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35
tobase Required. Specifies the base to convert to. Has to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35


技术细节

返回值: 这个数字转换为指定基数
返回类型: 字符串
PHP 版本: 4+

更多示例

示例

将八进制数转换为十进制数:

<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>
亲自试一试 »

示例

将八进制数转换为十六进制数:

<?php
$oct = "364";
echo base_convert($oct,8,16);
?>
亲自试一试 »

❮ PHP 数学参考