Answer the question
In order to leave comments, you need to log in
How to change the number system from 0-f to 0-zZ?
Tell me the algorithm for converting md5-hash from 12a0aef... (or directly from binary raw) to d1t5Zxs...
Answer the question
In order to leave comments, you need to log in
function baseConvert(string $number, int $fromBase, int $toBase) {
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
if ($fromBase == 10) {
$int = $number;
} else {
$int = 0;
$len = strlen($number);
$numberRev = strrev($number);
for ($i = 0; $i < $len; $i++) {
$int = gmp_add($int, gmp_mul($chars[strpos($chars, $numberRev[$i])], gmp_pow($fromBase, $i)));
}
}
$converted = '';
while (gmp_cmp($int, 0) > 0) {
list ($int, $remainder) = gmp_div_qr($int, $toBase);
$converted = $chars[gmp_intval($remainder)] . $converted;
}
return $converted;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question