Results 1 to 22 of 22

Thread: [RESOLVED] Boolean or Byte or Bit ?

Threaded View

  1. #17
    Fanatic Member
    Join Date
    Apr 2021
    Posts
    616

    Re: Boolean or Byte or Bit ?

    Very quick bit of code that seems to work for me, and much smaller than the one offered above:
    Code:
    Public BitArray(3, 1000000) As Byte
    
    Public Function getbit(point As Single, loc As Double)
    arrloc = 0: temppoint = point
    Do While temppoint > 8 'Gets the position along the dimensions
        temppoint = temppoint - 8: arrloc = arrloc + 1
        Loop
    getbit = BitArray(arrloc, loc) And 2 ^ (temppoint - 1)
    End Function
    
    Public Function setbit(point As Single, loc As Double, valu As Boolean)
    arrloc = 0: temppoint = point
    Do While temppoint > 8
        temppoint = temppoint - 8: arrloc = arrloc + 1
        Loop
    pos = BitArray(arrloc, loc) And 2 ^ (temppoint - 1)
    If pos = 0 And valu = True Then BitArray(arrloc, loc) = BitArray(arrloc, loc) + 2 ^ (temppoint - 1)
    If pos <> 0 And valu = False Then BitArray(arrloc, loc) = BitArray(arrloc, loc) - 2 ^ (temppoint - 1)
    setbit = getbit(point, loc)
    End Function
    getbit() pulls the value from the array as either zero (false) or non-zero (true)
    setbit() takes a true or false and places it at the designated location

    setbit(8, 100, True) Sets the 8th bit of the 100th value to true

    getbit(8, 100) pulls the value out (as zero or nonzero...shouldn't be difficult to have the output as boolean true or false)

    setbit(8, 100, False) Sets the same bit to false

    It isn't clean code, my code is generally function over form, but it's something that could be worked on from to get what you need...and yeah, took a little longer than 5 minutes but I haven't worked with the bit level in ages :-)
    Last edited by SmUX2k; Mar 11th, 2022 at 08:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width