TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: DAVID ROTHSCHILD
from: CHRIS GUNN
date: 1998-03-09 21:24:00
subject: Re: Individual bits

 DR>   How do can I read the individual bits that are inside a byte?
Howdy David,
Try the subroutine at the foot.  Don't forget to put DIM Kf%(16) before you
call it.  The remarks are intended for translating the keyboard status byte 
but will work for any integer.
If you only need to check one bit, just use the appropriate line in your 
de.
Something like:
Kf% = 255
CALL GetBinary(Kf%, Kf%())
LOCATE 10, 5: PRINT "Byte contents:  ";
FOR X% = 1 TO 16
    IF Kf%(X%) THEN PRINT "X"; ELSE PRINT "0";
    PRINT "  ";
NEXT X%
Should let you display what's in Kf% as Binary.  To reverse the process:
Kf% = Kf% OR 32  ' Would always set bit 6
   or
Kf% = Kf% AND 32  ' Would zero everything but bit 6.  If it results in
                  ' Kf% = 0 then bit 6 was not originally set.
Chris
=================================================================
SUB GetBinary (Kf%, Kf%())
'Returns bit status for Kf% in Kf%() dimension
'Source code must DIM Kf%(16)
        Kf%(16) = (32768 AND Kf%) MOD 3
        Kf%(15) = 16384 AND Kf%
        Kf%(14) = 8192 AND Kf%
        Kf%(13) = 4096 AND Kf%
        Kf%(12) = 2048 AND Kf%
        Kf%(11) = 1024 AND Kf%
        Kf%(10) = 512 AND Kf%
        Kf%(9) = 256 AND Kf%
        Kf%(8) = 128 AND Kf%: 'Always set
        Kf%(7) = 64 AND Kf%: '"
        Kf%(6) = 32 AND Kf%: '"
        Kf%(5) = 16 AND Kf%: '
        Kf%(4) = 8 AND Kf%: '
        Kf%(3) = 4 AND Kf%: '
        Kf%(2) = 2 AND Kf%: '
        Kf%(1) = 1 AND Kf%: '
        FOR X% = 1 TO 16
                IF Kf%(X%) THEN Kf%(X%) = 1 ELSE Kf%(X%) = 0
        NEXT X%
END SUB
--- FMail 0.96â
---------------
* Origin: BIZynet - Worldwide Business via the E-Ways (1:15/55.1)

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™.