Home  >  Article  >  Backend Development  >  php base_convert() base number conversion function_PHP tutorial

php base_convert() base number conversion function_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:181002browse

The base_convert() function converts numbers between arbitrary bases.

Grammar
base_convert(number,frombase,tobase) parameter description
number required. original value.
frombase required. The original base of the number.
tobase is required. The base to be converted.


*/

$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 the tobase representation of number. The base of number itself is specified by frombase. Both frombase and tobase can only be between 2 and 36 (inclusive). Numbers above decimal are represented by the letters a-z, such as a for 10, b for 11, and z for 35.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445382.htmlTechArticlebase_convert() function converts numbers between arbitrary bases. Syntax base_convert(number,frombase,tobase) Parameter Description number Required. original value. frombase required. The original base of the number...
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