Home  >  Article  >  Backend Development  >  How to use php base_convert function

How to use php base_convert function

藏色散人
藏色散人Original
2019-05-26 14:41:152397browse

php The base_convert function is used to convert numbers between arbitrary bases. Its syntax is base_convert(number, frombase,tobase). The parameter number is required and specifies the number to be converted; frombase is required and specifies the original base of the number.

How to use php base_convert function

#php How to use the base_convert function?

Definition and usage

base_convert() function converts numbers between arbitrary bases.

Syntax

base_convert(number,frombase,tobase);

Parameters

number Required. Specifies the number to be converted.

frombase Required. Specifies the original base of the number. 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.

tobase Required. Specifies the base to be converted. 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.

Return value: number converted to the specified base.

Return type: String

PHP version: 4

Example 1

Convert octal number to decimal number:

<?php
$oct = "0031";
echo base_convert($oct,8,10);
?>

Example 2

Convert octal number to hexadecimal number:

<?php
$oct = "364";
echo base_convert($oct,8,16);
?>

Example 3

Convert hexadecimal number to octal number:

<?php
$hex = "E196"; 
echo base_convert($hex,16,8); 
?>

The above is the detailed content of How to use php base_convert function. For more information, please follow other related articles on the PHP Chinese website!

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