DR> How do can I read the individual bits that are inside a byte?
Just use division to get the bit you want as the first bit.
FUNCTION Bitvalue%(Num%, Bit%)
FOR T% = 0 TO Bit%: Num% = Num% \ 2: NEXT
Bitvalue% = Num% AND 1
END FUNCTION
One important note is that this will change the value of
the integer you sent to the FUNCTION unless you specify
that it be passed as a value rather than a reference, by
enclosing that value in parentheses when passing it.
Bit5% = Bitvalue((number%), 5)
A somewhat faster method involves a precalculated table
of values to AND with.
DIM SHARED BITS(14) AS INTEGER
BITS(0) = 1: BITS(1) = 2: BITS(2) = 4: BITS(3) = 8: BITS(4) = 16
BITS(5) = 32: BITS(6) = 64: BITS(7) = 128: BITS(8) = 256
BITS(9) = 512: BITS(10) = 1024: BITS(11) = 2048: BITS(12) = 4096
BITS(13) = 8192: BITS(14) = 16767
FUNCTION BitVal% (Num%, Bit%)
IF Bit% = 15 THEN
BitVal% = -(Num% < 0)
ELSE
BitVal% = -((Num% AND BITS(Bit%)) > 0)
END IF
END FUNCTION
> ] You're trying to make me paranoid, but I'm on to your tricks
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
|