How to use php base_convert function

藏色散人
Release: 2023-02-22 19:46:01
Original
2351 people have browsed it

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);
Copy after login

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);
?>
Copy after login

Example 2

Convert octal number to hexadecimal number:

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

Example 3

Convert hexadecimal number to octal number:

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

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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!