Ejemplo n.º 1
0
<?php

if ($argc < 4) {
    echo "Usage: convert <number> <source-base> <target-base> [precision]" . PHP_EOL;
    die;
}
require __DIR__ . '/../src/Converter.php';
require __DIR__ . '/../src/NumberBase.php';
require __DIR__ . '/../src/DecimalConverter.php';
require __DIR__ . '/../src/ReplaceConverter.php';
require __DIR__ . '/../src/BaseConverter.php';
$source = new Riimu\Kit\BaseConversion\NumberBase(is_numeric($argv[2]) ? (int) $argv[2] : $argv[2]);
$target = new Riimu\Kit\BaseConversion\NumberBase(is_numeric($argv[3]) ? (int) $argv[3] : $argv[3]);
$converter = new Riimu\Kit\BaseConversion\BaseConverter($source, $target);
if ($argc > 4) {
    $converter->setPrecision($argv[4]);
}
echo "In Base " . $source->getRadix() . ": {$argv['1']}" . PHP_EOL;
echo "In Base " . $target->getRadix() . ": " . $converter->convert($argv[1]) . PHP_EOL;
Ejemplo n.º 2
0
<?php

if ($argc < 3) {
    echo "Usage efficiency.php <repeats> <length> [source-base] [target-base]" . PHP_EOL;
    exit;
}
require __DIR__ . '/../src/Converter.php';
require __DIR__ . '/../src/NumberBase.php';
require __DIR__ . '/../src/DecimalConverter.php';
require __DIR__ . '/../src/ReplaceConverter.php';
require __DIR__ . '/../src/BaseConverter.php';
echo "Test for efficiency of different algorithms available:" . PHP_EOL;
$sbase = isset($argv[3]) ? ctype_digit($argv[3]) ? intval($argv[3]) : $argv[3] : 2;
$tbase = isset($argv[4]) ? ctype_digit($argv[4]) ? intval($argv[4]) : $argv[4] : 16;
$source = new Riimu\Kit\BaseConversion\NumberBase($sbase);
$target = new Riimu\Kit\BaseConversion\NumberBase($tbase);
$repeats = (int) $argv[1];
$length = (int) $argv[2];
$max = $source->getRadix() - 1;
$number = [mt_rand(1, $max)];
for ($i = 1; $i < $length; $i++) {
    $number[$i] = mt_rand(0, $max);
}
$number = $source->getDigits($number);
class TimeoutException extends RuntimeException
{
}
$timer = 0;
function ticker()
{
    global $timer;