Sunday, October 30, 2022

HP 71B and TI-84 Plus CE: Binary Decimal Conversions Revised

HP 71B and TI-84 Plus CE:  Binary Decimal Conversions Revised


The programs presented can easily convert integers without the needs of lists or strings in input.  



HP 71B Programs:  BINDEC, DECBIN


No modules are required.


BINDEC (137 bytes)


100 DISP "BIN>DEC" @ WAIT .5

105 DESTROY A,B,C,D,E

110 INPUT "BIN? ";A

115 B=1 @ D=0 @ C=A

200 E=A/10 @ A=INT(E)

205 D=D+10*B*(E-A) @ B=2*B

210 IF A THEN 200

300 DISP "(2)";C;"="D


DECBIN (130 bytes)


100 DISP "DEC>BIN" @ WAIT .5

105 DESTROY A,B,C,D

110 INPUT "DEC? ";D

115 B=0 @ A=D @ C=1

200 E=D/2 @ D=INT(E)

205 B=B+C*(D<E)

210 C=C*10

215 IF D THEN 200

300 PRINT A;"=(2)";B



TI-84 Plus CE Programs:  BINDEC2, DECBIN2



BINDEC2


"V.2"

Disp "BIN>DEC"

Input "BIN? ",A

1→B:0→D:A→C

Lbl 2

A/10→E:iPart(E)→A

D+10*B*(E-A)→D

2*B→B

If A:Goto 2

Disp "(2) "+toString(C)+"= "+toString(D)



DECBIN2


"V.2"

Disp "DEC>BIN"

Input "DEC? ",D

0→B:D→A:1→C

Lbl 2

D/2→E:iPart(E)→D

B+C*(D<E)→B

10*C→C

If D:Goto 2

Disp toString(A)+"=(2) "+toString(B)


This is recommended for only integer values of 512 (decimal base) or less.  


Example


Decimal: 476  (DEC>BIN)

Result Binary:  111011100


Binary:  10111011 (BIN>DEC)

Result Decimal:  187



Source


Craig, John Clark.  119 Practical Programs For The TRS-80 Pocket Computer  TAB Books Inc.  Blue Ridge Summit, PA.  1982 pg. 133



Happy computing,

Eddie 



All original content copyright, © 2011-2022.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.