base_convert

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

base_convert在任意進(jìn)制之間轉(zhuǎn)換數(shù)字

說明

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

返回一字符串,包含 numbertobase 進(jìn)制的表示。number 本身的進(jìn)制由 frombase 指定。frombasetobase 都只能在 2 和 36 之間(包括 2 和 36)。高于十進(jìn)制的數(shù)字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35。

警告

由于使用內(nèi)部的 "double" 或 "float" 類型,base_convert() 的操作可能會導(dǎo)致大數(shù)值中的精度丟失。請參見本手冊的 浮點(diǎn)數(shù) 章節(jié)以便獲得更多詳細(xì)信息。

參數(shù)

number

要轉(zhuǎn)換的數(shù)字

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

參見

  • intval() - 獲取變量的整數(shù)值