base-convert
Convert an arbitrarily-long string from one numeric base to another, optionally zero-padding to a minimum column width.
Loading...
Searching...
No Matches
Functions.php File Reference

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. More...

Functions

 Wikimedia::base_convert ( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
 Convert an arbitrarily-long string from one numeric base to another, optionally zero-padding to a minimum column width.
 

Detailed Description

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html

Function Documentation

◆ base_convert()

Wikimedia\base_convert ( $input,
$sourceBase,
$destBase,
$pad = 1,
$lowercase = true,
$engine = 'auto' )

Convert an arbitrarily-long string from one numeric base to another, optionally zero-padding to a minimum column width.

Supports base 2 through 36; digit values 10-36 are represented as lowercase letters a-z. Input is case-insensitive.

Parameters
string$inputInput number
int$sourceBaseBase of the input number
int$destBaseDesired base of the output
int$padMinimum number of digits in the output (pad with zeroes)
bool$lowercaseWhether to output in lowercase or uppercase
string$engineEither "gmp", "bcmath", "php" or "auto" (default). In the case of "auto", the other engines ("gmp" and "bcmath") are used in the listed order in terms of preference if that PHP extension is actually loaded.
Returns
string|false The output number as a string, or false on error