base_convert 在任意进制之间转换数字

发表日期:2021-07-01 08:56:06 | 来源: | | 浏览(922) 分类:Math 函数

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($hexadecimal, 16, 2);
?>

以上例程会输出:

101000110111001100110100

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。