I wound up doing this:
Dim temp As Byte
Dim hexstring As String
temp = (Convert.ToByte(outputBank(7)) << 7) + _
(Convert.ToByte(outputBank(6)) << 6) + _
(Convert.ToByte(outputBank(5)) << 5) + _
(Convert.ToByte(outputBank(4)) << 4) + _
(Convert.ToByte(outputBank(3)) << 3) + _
(Convert.ToByte(outputBank(2)) << 2) + _
(Convert.ToByte(outputBank(1)) << 1) + _
Convert.ToByte(outputBank(0))
hexstring = Format(temp, "X2")
Which seems to give me what I need. Not sure how (in)efficient it is,
though.
Thanks for the reply.
"Andy Gaskell" <pubb AT hotmail DOT com> wrote in
news:O9**************@TK2MSFTNGP10.phx.gbl:
I first converted the BitArray to an Int32.
Dim result As Int32 = 0
For i As Int32 = 0 To outputBank.Length - 1
If outputBank(i) Then
result += System.Math.Pow(2, i)
End If
Next
MessageBox.Show(result.ToString("X"))
More info on formatting strings:
http://msdn.microsoft.com/library/de...y/en-us/cpguid
e/html/cpconstandardnumericformatstrings.asp
"Joel Moore" <as*******@asdaadad.com> wrote in message
news:Xn******************************@207.46.248.1 6... Maybe I'm just easily baffled after an all-nighter but I can't seem
to figure out how to represent a BitArray as a hexadecimal string.
For example:
Dim outputBank As New BitArray(8)
outputBank(0) = True
outputBank(1) = False
outputBank(2) = False
outputBank(3) = True
outputBank(4) = True
outputBank(5) = False
outputBank(6) = True
outputBank(7) = False
The hexadecimal string for the above array of bits would be "59".
How can I obtain that string? Is there an easy built-in method for
doing this or do I have to build something on my own?
Joel Moore