I found a previously asked question here, and am trying to implement Eineki's solution, however I'm on a 32bit system (I've installed Ubuntu 20.04 on an old laptop for testing). It was noted in the comments that the code wouldn't work on a 32bit system but there are workarounds, but they are not spelled out clearly enough for me. Unfortunately I'm pretty new with PHP and also with this website. I tried to comment there to ask for help and was told I couldn't because my account is new.
So here's how I modified that code, based on the instructions given in those comments. The instructions were:
Try to change the line occurence of $num % $b with fmod($num, $b) and $num/$b (and similar ones) with intdiv($nub, $b).
function base10to62($num, $b=62) {
$base='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$r = fmod($num % $b) ;
$res = $base[$r];
$q = floor(intdiv($num/$b));
while ($q) {
$r = fmod($q % $b);
$q = floor(intdiv($q/$b));
$res = $base[$r].$res;
}
return $res;
}
function base62to10( $num, $b=62) {
$base='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$limit = strlen($num);
$res=strpos($base,$num[0]);
for($i=1;$i<$limit;$i++) {
$res = $b * $res + strpos($base,$num[$i]);
}
return $res;
$base3_string1 = "212012222102200121211101010110220202222222211121102101011101111110021111210000102211101010101110101010101010220110000110111010101010000010002020001010200000022111111111110011120201111110000002002002002001011011101010000110010000000000";
$base10test = base_convert($base3_string1, 3, 10);
$base62test = base10to62($base10test);
$base62returntest = base62to10($base62test);
echo ("My base3_string1 is: ".$base3_string1."<br>");
echo ("My base10 number is: ".$base10test."<br>");
echo ("My base62 number is: ".$base62test."<br>");
echo ("My base62return hash is: ".$base62returntest."<br>");
As you can see, I have a base3 number I'm converting to base10. I'm doing this because it looks like Eineki's function wants base10 input. The base10 number I'm trying to convert is 8080064204040204462880280000286008662604880682228402402248426842, but when I attempt this the return is 0 and when I try to change it back of course the result is 0 because the input is 0.
I'm guessing I've misinterpreted Eineki's instructions on how to convert his code to work on a 32bit system. If anyone can help me correct this it would be appreciated.