Download


Description

I had an assignment for a class that involved changing a lot of numbers between bases by hand. I wrote this program to print out each step of the base conversion so that i could just copy it all into my notes and it would look like i did it by hand.
It's usually more fun to write a program that will do your homework for you than to do the homework itself.

I did not want to use the one-shot PHP functions like decbin, bindec, dechex, etc... because i wanted to see the individual steps of each operation so i could copy them onto my assignment. So here's the product of about a half hour of fiddling.

It will take an input (number)base and convert it to base10, then convert that base10 number into the final base you asked for.

Sample Output

$base10 = convert_from($number, $from_base);
$to_number = convert_to($base10, $to_base);	
print "Input: ($number)$from_base => ($base10)10 => ";
print "Output: ($to_number){$to_base}";

// Output
Converting from input (1101)2 to (x)10
       1 *  2^0    = (00000001)10     base10=1         
       0 *  2^1    = (00000000)10     base10=1         
       1 *  2^2    = (00000004)10     base10=5         
       1 *  2^3    = (00000008)10     base10=13        

Converting from internal (13)10 to (x)10
      13 /      10 = 1                r3  
       1 /      10 = 0                r1  

Input: (1101)2 => (13)10 => Output: (13)10

Online Demo

Please enter a number and its base. Then select the base you'd like to convert it to. Output will be all steps needed to: 1) Convert input (number)base into (x)10 2) Convert (x)10 into (output)to_base Number: Base: Convert to base:


Changelog / History