[2005] Reading Bits in a Byte Array
Okay here is the problem, I want to read a Base64 Encoded Message. Which can be converted back to a Byte Array. But I need to read the bits in specific positions to retrieve the information. In VB.Net is this possible or does the program need to be written in C# or C++?
I am using the following count to return the bit value
Code:
Public Function GetBits(byVal [Byte] as Byte, OffSet as Integer, Count as Integer) As Integer
Return ([Byte] >> Offset) + ((1 << Count) - 1)
End Function
The following should return the bit count that needs to be read for the total bits used to encode the profession in the string.
Code:
bits_per_profession = code * 2 + 4
Since they say it should be stored in the second byte since the first 8 bits are set aside for version information I am doing the following.
Code:
dim cBits as Integer = GetBits([ByteArray](2), 0, 2)
It just seems that doesn't return anything useful.
Re: [2005] Reading Bits in a Byte Array
To read a single bit you you can perform a logical AND operation:
vb Code:
Public Function GetBit(ByVal data As Byte, ByVal position As Integer) As Boolean
If position < 0 OrElse position > 7 Then
Throw New ArgumentException("Value must be within the range 0 to 7 inclusive.", "position")
End If
Dim mask As Byte = CByte(2 ^ position)
Return (data And mask) = mask
End Function
Re: [2005] Reading Bits in a Byte Array
Bits_per_proffession = code >>1 +4
You say that the byte you need is byte 2, but then you look at ByteArray(2). Since .NET is 0 based, that is the third byte in the array.
Re: [2005] Reading Bits in a Byte Array
Quote:
Originally Posted by Shaggy Hiker
Bits_per_proffession = code >>1 +4
You say that the byte you need is byte 2, but then you look at ByteArray(2). Since .NET is 0 based, that is the third byte in the array.
I explained it wrong.
Example of the data string
Code:
OwUUEOX9W4O1j7aExDKCs4yDACA
Example from the older strings
Code:
A0MAxm24oCbD/h3Qmol0JEAA
I am assuming it is Base64 Encoded Stream
Code:
Private mArr() as Byte
Public Sub GetBytes(byVal [String] as String)
mArr() = Convert.FromBase64String([String])
End Sub
Public Function DispVal(byVal [Byte] as Byte) as Integer
Return GetBits([Byte], 2, 6)
End Sub
For some reason that always returns really funny numbers. Also the correct code was
Code:
bits_per_profession = code * 2 + 4
The unknown is the code
If I reversed that when reading those bits would it return the right value?