在任意進位制之間轉換數字

base_convert

(PHP 4, PHP 5, PHP 7, PHP 8)

base_convert在任意進位制之間轉換數字

說明

base_convert(string $number, int $frombase, int $tobase): string

返回一字串,包含 numbertobase 進位制的表示。number 本身的進位制由 frombase 指定。frombasetobase 都只能在 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

範例

示例 #1 base_convert() 例子

<?php
$hexadecimal 
'A37334';
echo 
base_convert($hexadecimal162);
?>

以上例程會輸出:

101000110111001100110100

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *