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.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Using PHP's base_convert() to Convert Numbers Between Arbitrary Bases

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:

101000110111001100110100
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

base_convert
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.