search
Homephp教程php手册php中base_convert()进制数字转换函数实例,base_convert进制

php中base_convert()进制数字转换函数实例,base_convert进制

本文实例讲述了php中base_convert()函数进制数字转换的实现方法。分享给大家供大家参考。具体如下:

语法:base_convert(number,frombase,tobase)

参数 描述
number 必需,原始值.
frombase 必需,数字原来的进制.
tobase 必需,要转换的进制.

PHP实例代码如下:

复制代码 代码如下:

$hexadecimal='a37334';
echo base_convert($hexadecimal,16,2);   //转换为二进制输出101000110111001100110100
echo "
";
$number="123";
echo base_convert($number,10,2);    //转换为二进制输出1111011
echo "
";
echo base_convert($number,10,8);    //转换为八进制输出173
echo "
";
echo base_convert($number,10,16);    //转换为十六进制输出7b
$number2="100000101";
echo "
";
echo base_convert($number2,2,10);    //转换为十进制输出261
echo "
";
echo base_convert($number2,2,8);    //转换为八进制输出405


说明:返回一个字符串,包含 number 以 tobase 进制的表示。number 本身的进制由 frombase 指定,frombase 和 tobase 都只能在 2 和 36 之间(包括 2 和 36),高于十进制的数字用字母 a-z 表示,例如 a 表示 10,b 表示 11 以及 z 表示 35.

希望本文所述对大家的PHP程序设计有所帮助。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools