echo base_convert(4,10,2); // Output 100
echo "<br>";
echo base_convert(10,10,2); // Output 1010
Syntax
string base_convert(string $number, int $from_base, int $to_base);
| Parameter | DESCRIPTION |
|---|---|
| $number | Required : Input string representing number to convert. With a base higher than 10 is represented by Char. Here a is 10, b is 11 ... so z is 35. ( case in-sensitive ) |
| $from_base | Required : ( between 2 and 36 , inclusive ) |
| $to_base | Required : ( between 2 and 36 , inclusive ) |
echo base_convert(6,10,2); // Output 110
echo "<br>";
echo base_convert(42,10,2); // Output 101010
echo base_convert(10,10,8); // Output is 12
echo "<br>";
echo base_convert('15',10,8); // Output is 17
echo base_convert(12,10,16); // Output is c
echo "<br>";
echo base_convert('25',10,16); // Output is 19
echo base_convert(13,8,2); // Output is 1011
echo "<br>";
echo base_convert('25',8,2); // Output is 10101
echo base_convert(14,8,10); // Output is 12
echo "<br>";
echo base_convert(27,8,10); // Output is 23
echo base_convert(15,8,16); // Output is d
echo "<br>";
echo base_convert(30,8,16); // Output is 18
echo base_convert(15,16,2); // Output is 10101
echo "<br>";
echo base_convert(31,16,2); // Output is 110001
echo base_convert(14,16,8); // Output is 24
echo "<br>";
echo base_convert(32,16,8); // Output is 62
echo base_convert(13,16,10); // Output is 19
echo "<br>";
echo base_convert(33,16,10); // Output is 51
Math Functions
bindec(): Decimal equivalent of Binary string
decbin() Binary equivalent of decimal number
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.