function base_convert($numstring, $frombase, $tobase) { if (function_exists('gmp_strval')) { return gmp_strval(gmp_init($numstring, $frombase), $tobase); } else { if (function_exists('bi_base_convert')) { return bi_base_convert($numstring, $frombase, $tobase); } else { return oidUtilPhpBigInt::_base_convert($numstring, $frombase, $tobase); } } }
/* second argument of bi_from_str() and bi_to_str() - is the base of string representation of number. It can be from 2 to 36 inclusive */ $str = 'abcdef012789'; echo 'hex value of $str = [', $str, "]<br/>\n"; $b = bi_from_str($str, 16); echo 'decimal value of $b = [', bi_to_str($b), "]<br/>\n"; echo 'binary value of $b = [', bi_to_str($b, 2), "]<br/>\n"; /* string bi_base_convert(string $num, int $base_from, int $base_to) Converts string representation of $num from base $base_from to $base_to */ $num = '-12345678900987654321'; echo 'Decimal number [', $num, '] equals to [', bi_base_convert($num, 10, 36), '] by base 36', "<br/>\n"; /* basic functions */ echo '<h3>basic functions</h3>' . "\n"; $c = bi_add($a, $b); echo '$a + $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_sub($a, $b); echo '$a - $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_mul($a, $b); echo '$a * $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_div($a, $b); echo '$a / $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_mod($a, $b); echo '$a % $b = [', bi_to_str($c), "]<br/>\n"; $c = bi_abs($a);