Could I have some help calculating a checksum for receive data from a Video server?
The data is in Hex and the values and here is an example:
20 24 49 4C 30 31 37 38 37 39 CS
CS=Checksum
the cheksum is the 2's complement of the sum of the values.
If anyone have an algoritm or knows how to do it, please help me, thanks
The algorithm would be simple enough. Convert each three bytes (two if you inserted the spaces for readability) into a number, add them up, calculate the
two's complement, and see whether it matches.
- Dim sLine As String, I As Long
-
Dim lValue As Long, lSum As Long, lChecksum As Long
-
sLine = "20 24 49 4C 30 31 37 38 37 39 CS"
-
For I = 0 To 9
-
lValue = Val( "&h" & Mid$(sLine, I * 4, 3) )
-
lSum = lSum + lValue
-
Next
-
lChecksum = val( "&h" & Right$(sLine, 2) )
-
You now have the sum and the checksum. Do the two's complement thing (obviously I haven't read up on how, yet) and see whether they match.