当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > base_convert()函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 base_convert()函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 534 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The base_convert() function converts a number from one base to another.
base_convert()函数的作用是:在任意进制之间转换数字。

Syntax
语法

base_convert(number,frombase,tobase)

Parameter参数 Description描述
number Required. Original value
必要参数。定义初始值
frombase Required. Original base of number. Frombase 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.
必要参数。指定初始进制数。初始进制数的范围位于2和36之间(包括2和36);数值总位数如果大于10位,那么它将用a-z之间的字母表示,即:a表示10位,b表示11位,z表示35位数字
tobase Required. The base to convert to. Tobase 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.
必要参数。指定需要转换为的进制数。初始进制数的范围位于2和36之间(包括2和36);数值总位数如果大于10位,那么它将用a-z之间的字母表示,即:a表示10位,b表示11位,z表示35位数字


Example 1
案例1

Convert an octal number to a decimal number:
将一个八进制数字转换为十进制:

<?php
$oct = "0031";
$dec = base_convert($oct,8,10);
echo "$oct in octal is equal to $dec in decimal.";
?>

The output of the code above will be:
上述代码将输出下面的结果:

0031 in octal is equal to 25 in decimal.


Example 2
案例2

Convert an octal number to a hexadecimal number:
将一个八进制数字转换为十六进制:

<?php
$oct = "3648";
$hex = base_convert($oct,8,16);
echo "$oct in octal is equal to $hex in hexadecimal.";
?>

The output of the code above will be:
上述代码将输出下面的结果:

3648 in octal is equal to f4 in hexadecimal.

评论 (0) All

登陆 | 还没注册?