View Single Post
Old Jun 4th, 2005, 10:27 AM   #22
Komodo
Hobbyist Programmer
 
Komodo's Avatar
 
Join Date: May 2005
Location: Scranton, PA
Posts: 112
Rep Power: 0 Komodo is an unknown quantity at this point
Send a message via AIM to Komodo Send a message via MSN to Komodo
[php]
<?php
if($action==calculate){
///grabs the numbers that would be submitted in the form
$number1['number']=$_POST['number1'];
$num_sys_start['base']=$_POST['start'];
$num_sys_end=$_POST['end'];

///sets what the maximim value a digit can be
$num_sys_start['max']=$num_sys_start['base']-1;

////grabs the lenght of the number to be converted
$number1['length']=strlen($number1['number']);

/*in any number system, the first place always is one, the second is the 'modifier' times the place before it. In the base 10 number system, the first spot is 1, the second is 10(1*10), the third is 100(10*10), the fourth is 1000(100*10) and so on. this right here sets what each place is*/
$total=1;
$calculated=1;
while($calculated<=$number1['length']){
$num_calculate_values[$calculated]=$total;
$total=$total*$num_sys_start['base'];
$calculated++;
}

////after the last
$calculated--;
$int_start=0;
while($length1>=1){
$num_start_values[multiplied]=substr($number1['number'], $int_start, 1);
$calculated--;
$int_start++;
}

$calculated=1;
while($calculated<=$number1['length']){
$num_total_values['$calculated']=$num_start_values['$calculated']*$num_calculate_values['$calculated'];
$calculated++;
}

$calculated=1;
$result=0;
while($calculated<=$number1['length']){
$result=$result+$num_total_values['$calculated'];
$result++;
}
echo"$number1[number] has been converted from the base $start number system to the base $end number

system, and resulted in <span style=\"font-size: 14px; font-weight: strong;\">$result</span>.<br />";
}

echo"
<table>
<tr>
<td>
I want to take
</td>
<td>
<form method=\"post\" action=\"$PHP_SELF?action=calculate\">
<input type=\"text\" name=\"number1\" value=\"$number1[number]\" />
</td>
</tr>
<tr>
<td>
From the number system Base
</td>
<td>
<select name=\"start\">
<option value=\"2\">2</option>
<option value=\"3\">3</option>
<option value=\"4\">4</option>
<option value=\"5\">5</option>
<option value=\"6\">6</option>
<option value=\"7\">7</option>
<option value=\"8\">8</option>
<option value=\"9\">9</option>
</select>
</td>
</tr>
<tr>
<td>
To the number system Base
</td>
<td>
<select name=\"end\">
<option value=\"10\">10</option>
</select>
</td>
</tr>
<tr>
<td colspan=\"2\" align=\"center\">
<input type=\"submit\" value=\"Calculate!\" />
</td>
</tr>
</table
[/php]

Is it difficult to read?
Komodo is offline   Reply With Quote