TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: DAVID ROTHSCHILD
from: KURT KUZBA
date: 1998-03-17 08:02:00
subject: Individual bits

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.