Help with an algorithm
The data stream is from another file that I am importing and reviewing the
data line by line.
I will try to simplify the question and repost.
Thanks
"NickHK" wrote:
Dan,
Sorry, I don't understand the significance of the "Expected" section.
Also, don't know where this data stream is coming from, but can't you just
dump it in a byte array, then work in each byte as you go.
Private Sub CommandButton1_Click()
Dim ByteData() As Byte
Dim i As Long
Dim j As Long
Dim BinaryStr As String
'Sample data
'ReDim ByteData(1 To 3)
'ByteData(1) = 203
'ByteData(2) = 14
'ByteData(3) = 78
ByteData=<From data stream
For i = LBound(ByteData) To UBound(ByteData)
For j = 7 To 0 Step -1
If (ByteData(i) And 2 ^ j) 0 Then
'Then j bit is set
BinaryStr = BinaryStr & "1"
Else
BinaryStr = BinaryStr & "0"
End If
Next
Debug.Print "Byte: " & i, "Hex: " & Hex(ByteData(i)), "Dec: " &
ByteData(i), "Bit Set Count: " & BinaryStr
BinaryStr = ""
Next
End Sub
NickHK
"Dan" wrote in message
...
Need help in determining an algorithm to extract bit/byte information from
a
data stream. I know the where the bit/byte starts and the lenght to
extract,
but the problem is extracting the information correctly.
7 - 0 15 - 8 23 - 16 31 - 24 39 - 32 47 - 40 55 - 48
7654_3210 5432_1098 3210_9876 1098_7654 9876_5432 7654_3210 5432_1098
03 C2 FF A0 78 23 F6
The first and second rows above sequence is to show the bit location
within
the sequence. The third is the actual data that will be received.
The problem is that bit information (8 bits or less) is read right to left
and byte information (9 bits and greater) is read left to right.
Expected
Value Bit Length Variable
0 0 1 A
0 1 1 B
0 3 1 C
0 4 1 D
0 5 1 E
0 6 1 F
0 7 1 G
0 8 1 H
1 9 1 I
0 10 3 J
1 13 1 K
0 14 1 L
1 16 1 M
1 18 1 N
1 19 1 O
1 20 1 P
5A 24 8 Q
5A 32 8 R
002D 47 16 S
Thanks
|