|
-
May 1st, 2007, 04:56 PM
#1
Thread Starter
Addicted Member
[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.
Last edited by Daystar; May 1st, 2007 at 06:24 PM.
-
May 1st, 2007, 06:53 PM
#2
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
-
May 1st, 2007, 06:59 PM
#3
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.
My usual boring signature: Nothing
 
-
May 1st, 2007, 07:43 PM
#4
Thread Starter
Addicted Member
Re: [2005] Reading Bits in a Byte Array
 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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|