Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n11 (Volume 3, Issue 11)
Date: November 1982
Pages: 19
Suppose you have a large program, lots of data, and not enough memory. Is there any way to fit more in less?
If your integer data always falls in the range 0 to 15, you can store two numbers in each byte (character) of a string array (since there are 256 different character codes) by multiplying the first number by 16 and adding it to the second. In the accompanying program, line 70 stores two numbers (N1 and N2) in the Xth character of a string, and lines 120 and 130 read them back.
10 DIM A$(5)
20 FOR X=1 TO 5
30 INPUT N1
40 PRINT N1
50 INPUT N2
60 PRINT N2
70 LET A$(X)=CHR$ (N1*16+N2)
80 NEXT X
90 PRINT
100 PRINT
110 FOR X=1 TO 5
120 LET N1=INT (CODE A$(X)/16)
130 LET N2=CODE A$(X)-(N1*16)
140 PRINT N1,N2
150 NEXT X
SYNTACTIC SUM: 12486, 8K/16K
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.