Using PHP's base_convert() to Convert Numbers Between Arbitrary Bases
This article explains PHP's base_convert() function, detailing its signature, parameter meanings, supported base range, return value, and provides a concrete example that converts a hexadecimal string to its binary representation.
The PHP function base_convert() converts a number from one base to another, supporting bases between 2 and 36, where digits above 9 are represented by letters a‑z.
Signature:
string base_convert(string $number, int $frombase, int $tobase)Parameters:
$number : the number to be converted.
$frombase : the original base of the number (2‑36).
$tobase : the target base for conversion (2‑36).
Return value: a string containing the representation of $number in the target base.
Example:
<?php
$hexadecimal = 'A37334';
echo base_convert($hexadecimal, 16, 2);
?>Output:
101000110111001100110100Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
