10 'NUMERIC BASE CONVERSION
20 'WITH ASSISTANCE FROM NATIONAL BUREAU OF STANDARDS `HANDBOOK OF
30 'OF MATHMETICAL FUNCTIONS.'
40 'CONVERTED TO PC BASIC BY D. WATKINS 9/28/82
50 CLS
60 KEY OFF
70 LOCATE 2,21:PRINT "NUMERIC BASE CONVERSION PROGRAM"
80 DIM V$(20)
90 N$="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
100 'VARIABLE `M' IS THE HIGHEST
110 'BASE YOU MAY CONVERT FROM / TO
120 M=LEN(N$)
130 LOCATE 10,1 :PRINT "CONVERT NUMBERS FROM BASE:":PRINT "    Input a base between 2 and 36 (or 0 TO Exit)  ";
140 INPUT B1
150 'END PROGRAM?
160 IF B1=0 THEN 240
170 'TEST FOR VALID INPUT BASE
180 IF B1>1 THEN 210
190 PRINT "BASES 2 THROUGHT";M;"ONLY. SELECT AGAIN."
200 GOTO 130
210 IF B1>M THEN 190
220 PRINT :PRINT "                  TO BASE:":PRINT "    Input a base between 2 and 36 (or 0 TO Exit)  ";
230 INPUT B2
240 IF B1=0 OR B2=0 THEN CLS :LOCATE 12,27 :PRINT "Program end.": END
250 'TEST FOR VALID OUTPUT BASE
260 IF B2>1 THEN 290
270 PRINT "BASES 2 THROUGH ";M;"ONLY. SELECT AGAIN."
280 GOTO 220
290 IF B2>M THEN 270
300 CLS
310 LOCATE 3,23:PRINT "NUMERIC BASE CONVERSION PROGRAM":PRINT
320 LOCATE 11,1 :PRINT TAB(23);"From";TAB(58);"To"
330 CSR=14 :LOCATE 12,1 :PRINT TAB(22);"BASE";B1;TAB(56);"BASE";B2 :LOCATE 6,1
340 LOCATE 5,14 :PRINT "( Use any of these digits: "; MID$(N$,1,B1);" )"
345 LOCATE 6,30 :PRINT "( END TO Exit )"
350 LOCATE 8,1 :PRINT "Number in Base";B1;"to convert to a number in Base";B2 ;" "; :INPUT V$
360 FOR I=5 TO 9 :LOCATE I,1: PRINT SPACE$(80) : NEXT
365 IF MID$(V$,1,3)="END" THEN B1=0 :GOTO 240
370 IF MID$(V$,1,1)="0" THEN GOTO 340
380 'FIRST, CONVERT INPUT VALUE TO BASE 10
390 L=LEN(V$)
400 D=0:BAD=0
410 FOR I = 1 TO L
420 FOR J = 1 TO B1
430 IF MID$(V$,I,1)>MID$(N$,B1,1) THEN BAD =-1
440 IF MID$(N$,J,1)<>MID$(V$,I,1) THEN 460
450 D=D+INT((J-1)*(B1^(L-I))+.5)
460 NEXT J
470 NEXT I
480 IF BAD THEN 600
490 'NOW CONVERT BASE 10 VALUE TO
500 'DESIRED OUTPUT BASE
510 O$=""
520 X=INT(((D/B2)-INT(D/B2))*B2+1.5)
530 O$=MID$(N$,X,1)+O$
540 D=INT(D/B2)
550 IF D>0 THEN 520
560 'OUTPUT THE RESULT
570 LOCATE CSR,1 :PRINT TAB(29-LEN(V$));V$;TAB(62-LEN(O$));O$ :CSR=CSR+1
580 'LOOP BACK TO ENTER ANOTHER VALUE
590 GOTO 340
600 CLS :LOCATE 6,4 :PRINT "INVALID ENTRY:"
610 PRINT "THERE IS NO SUCH NUMBER `"V$"' (SIC) IN BASE"B1
620 GOTO 310
630 END