(PHP 4, PHP 5)
base_convert — 在任意進制之間轉換數字
說明
string base_convert ( string$number
, int $frombase
, int $tobase
)
返回一字符串,包含 number
以 tobase
進制的表示。number
本身的進制由
frombase
指定。frombase
和 tobase
都只能在
2 和 36 之間(包括 2 和 36)。高于十進制的數字用字母 a-z 表示,例如
a 表示 10,b 表示 11 以及 z 表示 35。
由于使用內部的 "double" 或 "float" 類型,base_convert() 的操作可能會導致大數值中的精度丟失。請參見本手冊的 浮點數 章節以便獲得更多詳細信息。
參數
number
要轉換的數字
frombase
The base number
is in
tobase
The base to convert number
to
返回值
number
converted to base tobase
范例
Example #1 base_convert() 例子
<?php
$hexadecimal = 'A37334';
echo base_convert($hexadecimal, 16, 2);
?>
以上例程會輸出:
101000110111001100110100
參見
intval() - 獲取變量的整數值