PHP base_convert() - Math Functions

What is base_convert Function?
How to convert a base value to binary number?

Explanation

The "base_convert()" function converts a number between arbitrary bases.

Syntax:


base_convert(number,frombase,tobase)

In the above syntax "number" is the orginal value, "frombase" is the original base of number, "tobase" the base to convert to.

Example :


<?php
$hex = 'A37334';
echo base_convert($hex,16,2);
?>
Result :

101000110111001100110100

In the above example the hexa decimal number "A37334" is converted to binary number as the "frombase" value is "16", "tobase" value is "2".

PHP Topics


Ask Questions

Ask Question