Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bool
#5
slenkar Wrote:so one byte is 8 bits or 8 'switches'?

so how would you say read or write a 'switch' in a byte? say I wanted to read switch 4 and read switch 5

if i have a byte array that is the size of the screen that is 32,24 which is 768 bytes

if I set up an array of bools it would only be 96 bytes Big Grin
ZX Basic supports BAND and bit shifting with SHR and SHL. In this case, you should use an array of 24 x 4 bytes => 24 Ulong and do the following (Note: This is *UNTESTED* :oops: )
Code:
DIM ar(23, 3) as Ubyte ' 24 x 32 bits.

#define BitTest(x, i)  Cast(Ubyte, 1 & (x >> i))
#define GetBool(a, i, j)  BitTest(a(ii, j >> 3), j & 7)
#define SetBool(a, i, j) a(i, j >> 3)  a(i, j >> 3) | 1 << (j & 7)
#define ResetBool(a, i, j) a(i, j >> 3)  SetBool(a, i, j): a(i, j >> 3) = a(i, j >> 3) ~ 1 << (j & 7)

IF GetBool(ar, 3, 20) THEN
...
END IF
Bittest does not come with ZX Basic, but is defined in a similar way it is here
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)