Source Code: | Run it! |
<?php
$maxBase=36;
$dg=array(0=>"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z");
if(isset($_GET['number'])AND isset($_GET['base'])AND isset($_GET['newbase'])){
$n1 = strval($_GET['number']);
$b1 = intval($_GET['base']);
$b2 = intval($_GET['newbase']);
if(($b1>$maxBase)OR($b2>$maxBase)){
echo '<font color="ff0000">'.
'ERROR: Neither base can be larger than 36!'.
'</font><hr/>';
}else{
$num=0;
while(strlen($n1)>0){
$num = $num * $b1;
$num = $num+array_search($n1{0},$dg);
$n1 = substr($n1, 1);
}
$n2="";
while($num>0){
$n2 = $dg[$num % $b2].$n2;
$num = floor($num/$b2);
}
echo "The number ".$n1." (base ".$b1.") in base ".$b2." is ".$n2.".<hr/>";
}
}
?>