After I have test.My poblem is rather to the line, I will try to code.
Code:
If Bit.And(crc1, 0x8000) Then
Let's at least get the first half of your troubles wrapped up ? try this (ie, copy and paste on top of the existing -
not-working? - function):
B4X:
Private Sub CRC16A(Buffer() As Byte) As Int
Dim Temp As Int
Dim crc1 As Int
crc1 = 0xFFFF
For i = 0 To Buffer.Length - 1
Temp = Bit.And(Buffer(i), 0xFF) * 0x0100
crc1 = Bit.Xor(crc1 ,Temp)
For j = 0 To 7
If Bit.And(crc1, 0x8000) <> 0 Then
crc1 = Bit.And( Bit.Xor((crc1 * 2), 0x1021), 0xFFFF)
Else
crc1 = Bit.And( (crc1 * 2), 0xFFFF)
End If
Next
Next
Return crc1
End Sub
with test it with this:
[CODE lang="b4x" highlight="16"]Dim bc As ByteConverter
Dim MessageString As String = "THEERA 2023"
Log("MessageString = " & MessageString)
Dim MessageBytes() As Byte = bc.StringToBytes(MessageString, "UTF-8")
Dim sb As StringBuilder
sb.Initialize
For i = 0 To MessageBytes.Length - 1
sb.Append(" ")
sb.Append(Bit.And(MessageBytes(i), 0xFF))
Next
Log("MessageBytes =" & sb.ToString)
Dim MessageCRC As Int = CRC16A(MessageBytes)
Log("CRC decimal = " & MessageCRC)
Log("CRC hexadecimal = " & Bit.ToHexString(MessageCRC))[/CODE]
and you should get something like this:
[CODE title="Log output" highlight="3,6"]Waiting for debugger to connect...
Program started.
MessageString = THEERA 2023
MessageBytes = 84 72 69 69 82 65 32 50 48 50 51
CRC decimal = 63001
CRC hexadecimal = f619[/CODE]
which matches CRC type CRC-16/CCITT-FALSE according to online CRC calculator at:
https://crccalc.com/?crc=THEERA 2023&method=crc16&datatype=ascii&outtype=0
but a better test would be to check the function input and results against your existing (working?) VB6 program.