TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: DAVID ROTHSCHILD
from: BUCKY CARR
date: 1998-03-11 07:42:00
subject: Individual bits

 DR>   How do can I read the individual bits that are inside a byte?
The following started life as QB code which I've reworked to VB code,
but you should be able to do something with it.  I did not originally
write this.
QB doesn't have a Byte data type, so you will be working with signed
integers.
 sBin = "01100101"
 iBin2Int(sBin) returns the integer value of sBin
 Public Function iBin2Int(sBin)
   Dim iY, iZ, iAX
   For iY = Len(sBin) To 1 Step -1
      If Mid$(sBin, iY, 1) = "1" Then
         iAX = iAX + (2 ^ iZ)
      End If
      iZ = iZ + 1
   Next
   iBin2Int = iAX
 End Function
 iDec = 233
 sInt2Bin(iDec) returns the byte value of iDec
 Public Function sInt2Bin(iDec)
   Dim iTDec, sBin
   iTDec = iDec
   Do While iTDec > 0
      If iTDec / 2 = iTDec \ 2 Then
         sBin = "0" & sBin
      ElseIf iTDec / 2  iTDec \ 2 Then
         sBin = "1" & sBin
      End If
      iTDec = iTDec \ 2
   Loop
   Do While Len(sBin) < 8               ' byte size only
      sBin = "0" & sBin
   Loop
   sInt2Bin = sBin
 End Function
--- PPoint 2.00
---------------
* Origin: Vanishing Point (1:15/7.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™.