A base converter from the Syntax series on number systems. Enter 10 to convert from decimal to another base, or enter the base you are converting from. The program then asks for the number and prints the result, using the letters A to Z as digits above 9, so any base up to 36 works. Negative numbers are allowed, and a digit that is too large for the base is reported as a non-legal number.
Answer Y to do another conversion. Don’t ask for base 1: the program would loop forever.
Published in Syntax April 1981 (Computer Number Systems III).
Source Code
10 CLS
20 PRINT "WHAT BASE? (ENTER 10 IF YOU WANT"
30 PRINT "TO GO FROM BASE 10 TO ANOTHER"
40 PRINT "BASE, OR ELSE ENTER THE BASE"
50 PRINT "TO CONVERT FROM)"
60 INPUT B
70 CLS
80 IF B=10 THEN GO TO 230
90 PRINT "WHAT IS THE NUMBER?"
100 INPUT A$
110 CLS
120 PRINT A$;" BASE ";B;"=";
125 LET PN=1+2*(CODE(A$)=220)
127 IF CODE(A$)=220 THEN LET A$=TL$(A$)
130 LET X=0
140 LET Y=CODE(A$)-28
150 IF Y<B THEN GO TO 180
160 PRINT "A NON-LEGAL NUMBER OF BASE ";B
170 GO TO 390
180 LET X=B*X+Y
190 LET A$=TL$(A$)
200 IF NOT A$=CHR$(1) THEN GO TO 140
210 PRINT PN*X;" BASE 10 "
220 GO TO 390
230 PRINT "WHAT BASE ARE YOU CONVERTING TO?"
240 INPUT B
250 CLS
260 PRINT "WHAT IS THE BASE 10 NUMBER?"
270 INPUT Y
280 CLS
290 PRINT Y;" BASE 10=";
295 IF Y<0 THEN PRINT "-";
297 LET Y=ABS(Y)
300 LET N=-1
310 LET N=N+1
320 IF NOT Y/B**N<B THEN GO TO 310
330 FOR I=0 TO N
340 LET X=B**(N-I)
350 PRINT CHR$(Y/X+28);
360 LET Y=Y-(Y/X)*X
370 NEXT I
380 PRINT " BASE ";B
390 PRINT
400 PRINT "DO YOU WANT ANOTHER CONVERSION?"
410 INPUT A$
420 IF CODE(A$)=62 THEN GO TO 10Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

