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

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 base_convert()函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 535 ::
收藏到网摘: 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

登陆 | 还没注册?