Home > Backend Development > PHP Tutorial > Example of base_convert() base number conversion function in PHP, base_convert base_PHP tutorial

Example of base_convert() base number conversion function in PHP, base_convert base_PHP tutorial

WBOY
Release: 2016-07-13 10:13:23
Original
1077 people have browsed it

Example of base_convert() base number conversion function in php, base_convert base

The example in this article describes the implementation method of base_convert() function in PHP to convert decimal numbers. Share it with everyone for your reference. The details are as follows:

Syntax: base_convert(number,frombase,tobase)

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

PHP example code is as follows:

Copy code The code is as follows:
$hexadecimal='a37334';
echo base_convert($hexadecimal,16,2); //Convert to binary output 101000110111001100110100
echo "
";
$number="123";
echo base_convert($number,10,2); //Convert to binary output 1111011
echo "
";
echo base_convert($number,10,8); //Convert to octal output 173
echo "
";
echo base_convert($number,10,16); //Convert to hexadecimal output 7b
$number2="100000101";
echo "
";
echo base_convert($number2,2,10); //Convert to decimal output 261
echo "
";
echo base_convert($number2,2,8); //Convert to octal output 405

Description: Returns a string containing number expressed in tobase base. The base of number itself is specified by frombase. Both frombase and tobase can only be between 2 and 36 (including 2 and 36). Numbers higher than decimal are represented by letters a-z, for example, a represents 10, b represents 11 and z represents 35. .

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/915440.htmlTechArticleExample of base_convert() base number conversion function in php, base_convert base This article tells the example of base_convert() in php Implementation method of function base number conversion. Share it with everyone for your reference...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template