Binary Number Converter
I am working on an Atari 800XL program that needs to convert a decimal number such as 255 to a binary digit such as 11111111. IF statements would work, but they seem very inefficient. Can this be done without IF statements?
Danny Maupin
Here is a program that does quick decimal-to-binary conversions:
10 NDIG=8: DIM BIN$(NDIG) 20 PRINT "DECIMAL NUMBER" ; 30 INPUT DCM: GOSUB 10000 40 PRINT "BINARY:" ;BIN$ 50 GOTO 20 10000 PK = 128: BIN$ = " " :WUN=1 10010 FOR LOOP = WUN TO NDIG 10020 LB=LEN(BIN$)+WUN 10030 BOO = DCM > = PK 10040 BIN$(LB)= CHR$(48+BOO) 10050 IF BOO THEN DCM = DCM - PK 10060 PK = PK/2 10070 NEXT LOOP 10080 RETURN
As listed, the program only converts numbers in the range 0–255. To expand its range to 0–65535, change the 8 in line 10 to 16 and the 128 in line 10000 to 32768.