Results 1 to 3 of 3

Thread: BitArray

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53

    BitArray

    I have a BitArray of 8 bits and I want to know the total value of the bits as if it were a byte.
    Code:
    Dim Mask As New BitArray(8, True)
    Mask(0) = False
    I'd like to now put them 8 bits (1 byte) into a byte varible, something like:
    Code:
    Dim MyByte as byte = mask
    Then in the above example MyByte would = 254

    Basically, assigning the 8 bits to a byte and being able to get the total value of that byte (which in this case would be the total of the 8 bits).

  2. #2
    Lively Member Tygur's Avatar
    Join Date
    Jul 2002
    Posts
    108
    You can use the CopyTo method to copy the bits to a one-byte-long byte array. That single byte will have the value you seek:
    VB Code:
    1. Dim Mask As New BitArray(8, True)
    2.         Mask(0) = False
    3.         Dim ByteArray(0) As Byte
    4.         Mask.CopyTo(ByteArray, 0)
    5.         Dim MyByte As Byte = ByteArray(0)

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    That works great, thanks.

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