Base_convert () PHP function

Source: Internet
Author: User
Definition and usage

The base_convert () function converts numbers in any hexadecimal format.

Syntax
Base_convert (number, frombase, tobase)
Parameters Description
Number Required. Original Value.
Frombase Required. The original hexadecimal number.
Tobase Required. The hexadecimal format to be converted.
Description

Returns a string containingNumber
ToTobase
Hexadecimal representation.Number
The hexadecimal StructureFrombase
.Frombase
AndTobase
It can only be between 2 and 36 (including 2 and 36 ). Numbers higher than decimal digits are represented by the letter A-Z. For example, a represents 10, B represents 11, and Z represents 35.

Example 1

Convert octal to decimal:

<? PHP
$ Oct = "0031 ";
$ Dec = base_convert ($ Oct, 8, 10 );
$ Oct of Echo "is equal to $ dec in decimal format. ";
?>

Output:

0031 Of The octal value is equal to 25 in decimal format.
Example 2

Convert the octal number to the hexadecimal number:

<? PHP
$ Oct = "364 ";
$ Hex = base_convert ($ Oct, 8, 16 );
$ Oct of Echo "is equal to $ hex in hexadecimal format. ";
?>

Output:

364 of octal is equal to F4.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.