Note: I wrote this in 3 separate programs to minimize my own confusion, called BINA, BINB, and BINC. They run inside a mother program, BINSHELL. BINSHELL is the only program that should be executed by the user.

{Text} indicates notes, which should not be added to the actual code

BINSHELL:

:Disp ""

:Disp "Enter Binary"

:Disp "Number"

:Input X

:If int(log(x)+1)>64

:Then

:Disp "Error: Too many"

:Disp "Digits"

:Else

:prgmBINA

:prgmBINB

:prgmBINC

:Disp ""

:Disp ""

:Disp ""

:Disp X

:Disp " =" {15 spaces before =}

:sum(L3)

BINA:

{this counts the number of digits (Y) in the binary number (X) and creates a list of descending powers of 2 with that many spaces, starting with 2^(Y-1) and repeating until 2^0}

:ClrList L1

:int(log(x)+1)->Y {-> represents the "sto" button, directly above on/off} {int(log(x)+1)= the number of digits in the binary number}

:1->Z

:Lbl A

:2^(Y-Z)->L1(Z)

:If Z<Y

:Then

:Goto A

:Else

:End

BINB:

{This basically separates the binary number into it's individual digits and stores them in L2 so that they match with their corresponding power of 2 in L1}

:X->U

:ClrList L2

:1->C

:LblA

:int(U/10^(Y-C))->B

:B->L2(C)

:U-(B*10^(Y-C))->U

:C+1->C

:If C<Y

:Then

:Goto A

:Else

:End

BINC:

{This multiplies the power of 2 from L1 by the binary digit in L2 and stores the result in L3. By far the simplest third of the code}

:ClrList L3

:1->C

:LblA

:L1(C)*L2(C)->L3(C)

:C+1->C

:If C<Y

:Then

:Goto A

:Else

:End