10 CLS
20 KEY OFF
30 PRINT "NUMERIC BASE CONVERSION"
40 PRINT
50 N$="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
60 REM  -- VARIABLE 'M' IS THE HIGHEST
70 REM  -- BASE YOU MAY CONVERT FROM / TO
80 M=LEN(N$)
90 PRINT "FROM BASE (0 TO END) ";
100 INPUT B1
110 REM  -- END PROGRAM?
120 IF B1=0 THEN 550
130 REM  -- TEST FOR VALID INPUT BASE
140 IF B1>1 THEN 170
150 PRINT "BASES 2 THROUGH";M;"ONLY. SELECT AGAIN. "
160 GOTO 90
170 IF B1>M THEN 150
180 PRINT "TO BASE ";
190 INPUT B2
200 IF B2=0 THEN 90
210 REM  -- TEST FOR VALID OUTPUT BASE
220 IF B2>1 THEN 250
230 PRINT "BASES 2 THROUGH";M;"ONLY. SELECT AGAIN."
240 GOTO 180
250 IF B2>M THEN 230
260 PRINT "VALUE ";
270 INPUT V$
280 IF V$="0" THEN 180
290 REM  -- FIRST, CONVERT INPUT VALUE TO BASE 10
300 L=LEN(V$)
310 D=0:BAD=0
320 FOR I=1 TO L
330 FOR J=1 TO B1
340 IF MID$(V$,I,1)>MID$(N$,B1,1) THEN BAD=-1
350 IF MID$(N$,J,1)<>MID$(V$,I,1) THEN 370
360 D=D+INT((J-1)*(B1^(L-I))+.5)
370 NEXT J
380 NEXT I
390 IF BAD THEN 510
400 REM  -- NOW CONVERT BASE 10 VALUE TO
410 REM  -- DESIRED OUTPUT
420 O$=""
430 X=INT(((D/B2)-INT(D/B2))*B2+1.5)
440 O$=MID$(N$,X,1)+O$
450 D=INT(D/B2)
460 IF D>0 THEN 430
470 REM  -- OUTPUT THE RESULT
480 PRINT V$;" BASE";B1;"IS ";O$;" BASE";B2
490 REM  -- LOOP BACK TO ENTER ANOTHER VALUE
500 GOTO 260
510 PRINT "INVALID ENTRY:"
520 PRINT "THERE IS NO SUCH NUMBER '"V$"' (SIC) IN BASE"B1
530 PRINT
540 GOTO 90
550 END