Esempio n. 1
0
<?php

function hex_to_dec($hex)
{
    $len = strlen($hex);
    $dec = 0;
    $multiplier = 1;
    for ($i = $len - 1; $i >= 0; $i--) {
        $dec += $multiplier * strpos('0123456789abcdef', $hex[$i]);
        $multiplier *= 16;
    }
    return $dec;
}
foreach (file($argv[1]) as $line) {
    echo hex_to_dec(strtolower(trim($line))) . "\n";
}
Esempio n. 2
0
     }
 }
 if (!$skip_random) {
     switch ($question['type']) {
         case 'area':
             if (!isset($excluded[$tmp_question_ID])) {
                 $csv .= ',"';
                 if (isset($individual[$tmp_screen][$tmp_question_ID]) and $individual[$tmp_screen][$tmp_question_ID] != '') {
                     $answer_parts = explode(';', $individual[$tmp_screen][$tmp_question_ID]);
                     if (count($answer_parts) > 1) {
                         $csv .= hex_to_dec($answer_parts[1]);
                     }
                 }
                 $csv .= '"';
                 if ($is_random) {
                     $csv .= ',"' . hex_to_dec(ltrim($question['correct'], ',')) . '"';
                 }
             }
             break;
         case 'blank':
             $correct_parts = explode(',', $question['correct']);
             $tmp_answers = isset($individual[$tmp_screen][$tmp_question_ID]) ? explode('|', $individual[$tmp_screen][$tmp_question_ID]) : array_fill(0, count($correct_parts), 'u');
             for ($partID = 1; $partID < count($correct_parts); $partID++) {
                 if (substr($tmp_exclude, $partID - 1, 1) == '0') {
                     $csv .= ',';
                     if ($tmp_answers[$partID] != 'u') {
                         $csv .= '"' . str_replace("\n", ' ', str_replace("\r", ' ', $tmp_answers[$partID])) . '"';
                     }
                     if ($is_random) {
                         $csv .= ',' . $correct_parts[$partID];
                     }