I made a function that can be used for converting numbers to any base you wish.. instead of returning a string of pre-defined index of characters (i.e. 0-9a-z) you could simply make your own of any length using the array of indexes it returns.
I looked around and didn't see anybody made one, I needed one for a simple compression algorithm with only numbers, I've not actually made it yet but this was an initial idea.
<?php
function ConvertBase($Input,$Base=10) {
$Input=gmp_init($Input);
$Result=array();
for($i=0;$i<1||gmp_sign($Input)==1;$i++) {
$Result[]=gmp_intval(gmp_mod($Input,$Base));
$Input=gmp_div_q($Input,$Base);
}
$Result=array_reverse($Result);
return($Result);
}
$Input = '1189998819991197253';
$Chars = '0123456789abcdefghijklmnopqrstuvwxyz';
$Base = strlen($Chars);
$Result = ConvertBase($Input,$Base);
for($i=0;$i<count($Result);$i++)
$Result[$i]=$Chars{$Result[$i]};
printf("gmp_strval: %s\r\n",gmp_strval($Input,36));
printf("BaseConvert: %s\r\n",implode($Result));
?>
The example shows a familiar result of course, but the idea of this function was so that you can use whatever base you wish, and display entirely your own output to represent any number of choice.
Also, for those who wish to do bitwise shifting, it's quite simple.. to shift left, just multiply the number by pow(2,x), and to shift right, divide by pow(2,x).
<?php
function gmp_shiftl($x,$n) { return(gmp_mul($x,gmp_pow(2,$n)));
}
function gmp_shiftr($x,$n) { return(gmp_div($x,gmp_pow(2,$n)));
}
?>
Have fun,
Nitrogen.