Hi,
I have to connect to device based on 8 bit AVR Atmel uP, and using CRC8 algorithm in comunication protocol. The Function to calculater CRC8 written in VB.Net is working well but i can't translate it to B4A - I will appreciate any help...
and my code in B4A - it is not working im getting wrong CRC with "-" sign
what Iam doing wrong ?
I have to connect to device based on 8 bit AVR Atmel uP, and using CRC8 algorithm in comunication protocol. The Function to calculater CRC8 written in VB.Net is working well but i can't translate it to B4A - I will appreciate any help...
B4X:
Function Docrc8(s As String) As Byte
Dim j As Byte
Dim k As Byte
Dim crc8 As Byte
crc8 = 0
For m = 1 To Len(s)
x = Asc(Mid(s, m, 1))
For k = 0 To 7
j = 1 And (x Xor crc8)
crc8 = Fix(crc8 / 2) And &HFF
x = Fix(x / 2) And &HFF
If j <> 0 Then
crc8 = crc8 Xor &H8C
End If
Next k
Next
Docrc8 = crc8
End Function
and my code in B4A - it is not working im getting wrong CRC with "-" sign
B4X:
Sub docrc8(s As String) As Byte
Dim j As Byte
Dim k As Byte
Dim crc8 As Byte = 0
Dim m As Byte
Dim x As Int
For m = 1 To sf.Len(s)
x = Asc(sf.Mid(s, m, 1))
For k = 0 To 7
j = Bit.AND(1, Bit.Xor(x, crc8))
crc8 = Bit.AND(NumberFormat2((crc8/2),2,0,0,False),0xFF)
x = Bit.AND(NumberFormat2((x/2),2,0,0,False),0xFF)
If j <> 0 Then
crc8 = Bit.Xor(crc8 ,0x8C)
End If
Next
Next
Return crc8
End Sub
what Iam doing wrong ?