I have found
from https://www.b4x.com/android/forum/threads/xor-checksum-hell.37364/#post-220250
Post is too old to reply.
Question is still alive - what wrong with this code? It produces result "a bit" to big
I have tested it for "P0#i100/" ($30 $23 $69 $31 $30 $30 $2F) - it gives C9, but should be B9
B4X:
Sub GetCheckSum(MyData As String) As String
Dim CRC = 255 As Int
If Not(MyData.StartsWith("02")) Then
MyData = "02" & MyData
End If
Try
Dim CRC = 255 As Int
Do While MyData.Length >= 2
CRC = Bit.Xor(CRC, Bit.ParseInt(MyData.SubString2(0, 2), 16))
MyData = MyData.SubString(2)
Loop
Dim tmp(1) As Byte
tmp(0) = CRC
Dim tmpStr = conv.HexFromBytes(tmp) As String
Return tmpStr
Catch
Log("Couldn't convert! Error was: " & LastException.Message)
Return("00")
End Try
End Sub
from https://www.b4x.com/android/forum/threads/xor-checksum-hell.37364/#post-220250
Post is too old to reply.
Question is still alive - what wrong with this code? It produces result "a bit" to big
I have tested it for "P0#i100/" ($30 $23 $69 $31 $30 $30 $2F) - it gives C9, but should be B9
Last edited: