PHP base_convert

I wrote a simple tool to visualize numbers in different bases to help solve a math problem I was thinking about
the other day. It uses PHP. If you share this script make sure to sanitise data.

<h1> Convert numbers </h1>
Use this form to convert numbers between different bases. <br/>
This can be useful for visualizating numbers in different bases. <br/>

Input base number:<br/>
<input type=”text” name=”base_in” value=”10″/><br/>
Numbers To Convert (1 per line)<br/>
<textarea name=”input_data” rows=”5″ cols=”20″>
if( isset( $_REQUEST["input_data"] ) )
echo $_REQUEST["input_data"];
Output base number:
<br/><input type=”text” name=”base_out” value=”2″/><br/>
<input type=”submit” name=”submit” value=”submit”/><br/>

if( isset( $_REQUEST["input_data"] ) )
$base_in = $_REQUEST["base_in"];
$base_out = $_REQUEST["base_out"];
$input_data = $_REQUEST["input_data"];
$lines = preg_split(“/(\r?\n)/”, $input_data);
$lines_count = count( $lines );

echo “<b> output in base $base_out</b><br/>”;
foreach( $lines as $line)
// do stuff with $line
echo base_convert( $line, $base_in, $base_out).”\n<br/>”;


Leave a Reply

Your email address will not be published. Required fields are marked *