English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

base_convert() function in PHP

Body2to36between10The numbers in the number are represented by the letters az, that is, a is10 、、 d is13, z is35etc.

The base_convert() function can convert a number from one base to another, for example, converting an octal number to a decimal number. The base mentioned here should be between

Syntax

base_convert(num, original_base, to_base)

  • Parameter-num

  • The number to be converted-original_base2to36between10The numbers in the number are represented by the letters az, that is, a is10 、、 d is13, z is35etc.

  • to_base-The base to be converted to. The base mentioned here should be between2to36between10The numbers in the number are represented by the letters az, that is, a is10 、、 d is13, z is35etc.

Return

The base_convert() function returns a string representing the number converted to the required base.

Example

<?php
   $res = "0040";
   echo base_convert($res,8,10);
?>

Output Result

32

Example

<?php
   $res = "D365";
   echo base_convert($res,16,8);
?>

Output Result

151545

Example

Let's look at another example-

<?php
   $res = "101101";
   echo base_convert($res,2,16);
?>

Output Result

2d