How to use base convert in PHP

This article describe about base_convert() Function in PHP.
  • 1387

base_convert() Function

For convert a number from one base to another by base_convert() function.

Syntax

base_convert (number, frombase, tobase)

 

Parameter Description
number Required. original value
frombase Required. Original base of number. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.
tobase Required. The base to convert to. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35.

Example 1

Convert octal to decimal number.

<html>
<body>
<?php
$oct = "0036";
$dec = base_convert($oct,8,10);
echo "$oct in octal is equal to $dec in decimal.";
?>
</body>
</html>

 

Output


baseconverphp1.jpg

 

Example 2

Convert octal to hexadecimal number.

 

<html>
<body>
<?php
$oct = "400";
$hex = base_convert($oct,8,16);
echo "$oct in octal is equal to $hex in hexadecimal.";
?>
</body>
</html>

 

Output


baseconverphp2.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.