Decimal/Hex/Bin Convertor

Developer(s): Vincent Lyon
Date: 1984
Type: Program
Platform(s): TS 2068
Tags: Utility

A small menu-driven tool for machine code and user-graphics work: 1 converts a decimal number to four-digit hex, 2 a four-digit hex number to decimal, 3 an eight-digit binary number to decimal, and 4 ends the program (press ENTER to clear memory with NEW). Hex must be typed as four digits (05C3, not 5C3; caps lock is switched on for it), and binary as exactly eight digits, or it tells you there were not enough or too many.

Corrected so it runs: line 1018 was printed PRINT AT ,15,0 (with a stray comma), which stops the program with Nonsense in BASIC as soon as the menu appears; it now reads PRINT AT 15,0. The author notes a TS1000 version could be written by changing the CHR$ codes; only the TS2068 version is printed.

Published in The Plotter December 1984 (Small Tool).

Image Gallery

Source Code

   5 CLS
  10 GO TO 1000
 100 DIM H$(4)
 105 LET p=4
 110 LET h$="0000"
 115 PRINT AT 20,0;"                                ";AT 20,0; FLASH 1;">"; FLASH 0;" Enter the decimal number."
 120 INPUT d
 122 LET e=d
 125 PRINT AT 20,0;"                                "
 130 LET n=INT (d/16)
 131 LET rr=(d-16*n+48)
 132 IF rr>57 THEN LET rr=rr+7
 135 LET h$(p)=CHR$ (rr)
 140 LET d=n
 145 LET p=p-1
 150 IF d>0 THEN GO TO 130
 160 PRINT AT 20,0;e;" Hex Value is ";h$
 170 GO TO 1000
 200 PRINT AT 20,0;"                                ";AT 20,0; FLASH 1;">"; FLASH 0;" Enter the four digit hex."
 202 POKE 23658,8
 205 INPUT h$
 210 LET d=0
 215 FOR p=1 TO 4
 217 LET rr=(CODE (h$(p))-48)
 218 IF rr>9 THEN LET rr=rr-7
 220 LET d=d*16+(rr)
 225 NEXT p
 230 PRINT AT 20,0;"                                ";AT 20,0;h$;" Decimal value is ";d
 235 POKE 23658,0
 240 GO TO 1000
 300 DIM a$(8)
 305 LET o=0
 307 PRINT AT 21,9;"▒"
 310 PRINT AT 20,0;"                                ";AT 20,0; FLASH 1;">"; FLASH 0;" Enter BIN code."
 314 INPUT b$
 315 LET a$=b$
 316 LET i=LEN b$
 317 IF i<>8 THEN GO TO 400
 320 LET b=128
 330 FOR f=1 TO 8
 340 LET q=VAL a$(f)
 350 LET o=o+(q*b)
 360 LET b=b/2
 370 NEXT f
 375 PRINT AT 21,9;" "
 380 PRINT AT 20,0;"                                ";AT 20,0;a$;" BIN is ";o;" decimal."
 390 GO TO 1000
 400 IF i<8 THEN PRINT FLASH 1;AT 20,0;" NOT ENOUGH DIGITS WERE ENTERED "
 410 IF I>8 THEN PRINT FLASH 1;AT 20,0;" TOO MANY DIGITS WERE ENTERED "
 420 PAUSE 100
 430 PRINT AT 20,0;"                                "
 440 GO TO 300
 500 CLS
 510 PRINT AT 10,0;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒";AT 12,4;"EXIT COMMAND EXECUTED","  PRESS ENTER TO CLEAR MEMORY";AT 15,0;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
 515 PAUSE 4E4
 520 NEW
1000 PRINT AT 5,0;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒";AT 7,3; INVERSE 1;"DECIMAL/HEX/BIN CONVERTOR";
1010 PRINT AT 9,6;"1) DECIMAL TO HEX";AT 10,6;"2) HEX TO DECIMAL";AT 11,6;"3) BIN TO DECIMAL";AT 12,6;"4) EXIT PROGRAM"
1015 PRINT AT 13,0;"▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
1017 PRINT ,,"  Enter your choice 1 to 4"
1018 PRINT AT 15,0; FLASH 1;">"
1019 BEEP .15,10
1020 INPUT S
1025 PRINT AT 15,0;" "
1030 IF S<1 OR S>4 THEN GO TO 1000
1035 IF S=4 THEN LET S=5
1040 GO TO S*100
1050 STOP
1060 SAVE "conv" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.