Program to covert numbers to Hex, Octal Decimal, and Binary.
Related Products
Enter a number in any of the following bases: decimal, binary, octal, hexadecimal. Get the equivalent in the other bases. 16K.
Source Code
100 PRINT "ADD ONE OF THESE PREFIXES TO NO.B=BINARY D=DECIMAL O=OCTAL H=HEX" 110 INPUT N$ 120 LET B$=N$(1) 130 LET N$=N$(2 TO LEN N$) 140 IF B$="B" THEN LET BB=2 150 IF B$="O" THEN LET BB=8 160 IF B$="D" THEN LET BB=10 170 IF B$="H" THEN LET BB=16 180 IF BB<>10 THEN GOSUB 500 190 IF BB=10 THEN LET ND=VAL N$ 200 IF BB<>2 THEN LET B=2 210 GOSUB 400 220 LET M$=Y$ 230 IF BB=2 THEN LET M$=N$ 240 IF BB<>8 THEN LET B=8 250 GOSUB 400 260 LET O$=Y$ 270 IF BB=8 THEN LET O$=N$ 280 IF BB<>16 THEN LET B=16 290 GOSUB 400 300 LET H$=Y$ 310 IF BB=16 THEN LET H$=N$ 320 PRINT "NUMBER IN OTHER BASES" 330 PRINT "DECIMAL:";ND 340 PRINT "BINARY :";M$ 350 PRINT "OCTAL :";O$ 360 PRINT "HEXADEC:";H$ 370 STOP 380 GOTO 100 400 LET Z=ND 410 LET Y$="" 420 LET Y=Z 430 LET Z=INT (Z/B) 440 LET Y=Y-B*Z 450 LET K=28 460 IF Y>9 THEN LET K=21+(7*(B=16)) 470 LET Y$=CHR$ (Y+K)+Y$ 480 IF Z>0 THEN GOTO 420 490 RETURN 500 LET ND=0 510 LET Z=0 520 FOR I=1 TO LEN N$ 530 LET Z=CODE N$(I) 540 LET K=28 550 IF Z>37 THEN LET K=21+(7*(BB=16)) 560 LET ND=ND*BB+Z-K 570 NEXT I 580 RETURN 9550 CLS 9560 SAVE "BAS%E" 9570 GOTO 100