Bases converts numbers between any two bases from 2 to 36. It asks for the base to convert from, the base to convert to and the value, prints the result and offers another conversion.
The REM reads “(C) Dilwyn Jones, 1984”. Its document file was lost from the disk image.
Program Analysis
CHECK rejects characters that are not digits of the source base, and CONVERT$ builds the result string.
It came from a QL owner’s floppy copies of QUANTA and IQLUG library material, imaged double-stepped so that only half of each disk survived; this file read back complete. The download holds the files exactly as recovered and a QL5A floppy image, Bases.img, with the same files and their QDOS headers. Mount the image as FLP1_ (drop it on the QLRun page, or use it as a floppy image in sQLux, QPC2 or Q-emuLator) and type lrun flp1_BASES.
Tested in QLRun with the JS ROM: 1985 in base 10 converted to binary.
Source Code
100 REMark base to base conversion program
110 REMark --- (C) Dilwyn Jones, 1984 ---
120 MODE 8:PAPER 0:WINDOW 512,256,0,0:CLS
130 WINDOW 452,220,30,16:BORDER 2,255
140 PAPER 6:INK 0:CSIZE 2,0
150 CLS:PAPER 0:INK 6:PRINT' NUMBER BASE CONVERSIONS ':PAPER 6:INK 0
160 WINDOW 444,206,34,28:CLS
170 REPeat program
180 CLS
190 REPeat loop2
200 REPeat loop
210 INPUT'Convert from base ';temp$
220 IF CHECK(temp$,10)=1 THEN EXIT loop
230 END REPeat loop
240 con_from=temp$
250 IF con_from>=2 AND con_from<=36 THEN EXIT loop2
260 PRINT'Error...base 2-36 only...'
270 END REPeat loop2
280 REPeat loop2
290 REPeat loop
300 INPUT'Convert to base ';temp$
310 IF CHECK(temp$,10)=1 THEN EXIT loop
320 END REPeat loop
330 con_to=temp$
340 IF con_to>=2 AND con_to<=36 THEN EXIT loop2
350 PRINT'Error...base 2-36 only...'
360 END REPeat loop2
370 REPeat loop
380 INPUT'Value:';a$
390 IF CHECK(a$,con_from)=1 THEN EXIT loop
400 END REPeat loop
410 PRINT'In Base ';con_to;' = ';CONVERT$(a$,con_from,con_to)
420 PRINT\'Any more (Y/N)?';
430 REPeat loop
440 k$=INKEY$(-1)
450 IF k$='y' THEN k$='Y'
460 IF k$='n' THEN k$='N'
470 IF k$='Y' OR k$='N' THEN PRINT k$:EXIT loop
480 END REPeat loop
490 IF k$='N' THEN EXIT program
500 END REPeat program
510 PRINT\'PROGRAM FINISHED.'
520 DEFine FuNction CHECK(num,base)
530 LOCal t$,valid,a
540 t$='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'(1 TO base)
550 valid=1
560 FOR a=1 TO LEN(num)
570 IF (num(a) INSTR t$)=0 THEN valid=0
580 END FOR a
590 IF valid=0 THEN PRINT'Error...Invalid character...'
600 IF num='' THEN PRINT"Dont't be silly...":valid=0
610 RETurn valid
620 END DEFine CHECK
630 DEFine FuNction CONVERT$(num,from,tobase)
640 LOCal sum,num2$,char,digit,conv$,remn,loop
650 sum=0:num2$=num:conv$=''
660 FOR char=LEN(num2$) TO 1 STEP -1
670 digit=CODE(num2$(char))
680 sum=sum+(digit-48-7*(digit>=65)-32*(digit>=97))*(from^(LEN(num2$)-char))
690 END FOR char
700 REPeat loop
710 remn=INT(sum-(tobase*INT(sum/tobase))+.5)
720 sum=INT(sum/tobase)
730 conv$=CHR$(remn+48+7*(remn>9))&conv$
740 IF sum=0:EXIT loop
750 END REPeat loop
760 RETurn conv$
770 END DEFine CONVERT$Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
