Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
base_convert() function in PHP
The base_convert() function converts a number from one base to another, for example, octal number to decimal number. The base mentioned here should be between 2 and 36. Digits in numbers with a base greater than 10 is represented with the letters a-z i.e a is 10, , d is 13, z is 35, etc.
Syntax
base_convert(num, original_base, to_base)
Parameters
num − The number to convert
original_base − The original base. The base mentioned here should be between 2 and 36. Digits in numbers with a base greater than 10 is represented with the letters a-z i.e a is 10, , d is 13, z is 35, etc.
to_base − The base to convert to. The base mentioned here should be between 2 and 36. Digits in numbers with a base greater than 10 is represented with the letters a-z i.e a is 10, , d is 13, z is 35, etc.
Return
The base_convert() function returns a string representing the number converted to the desired base.
Example
<?php $res = "0040"; echo base_convert($res,8,10); ?>
Output
32
Example
<?php $res = "D365"; echo base_convert($res,16,8); ?>
Output
151545
Example
Let us see another example −
<?php $res = "101101"; echo base_convert($res,2,16); ?>
Output
2d
