Hello,
I need help for a Foxpro CRC16 compute for a hexa string like :
A0000101
The CRC16 /Buypass for this string is 06 35
i have 2 examples :
--------------------------------
I try this but i'm stuck :
I verify the calculation for that string on to CRC16/BUYPASS and is corect
I have also other examples in C++
Thank you very much for help!
I need help for a Foxpro CRC16 compute for a hexa string like :
A0000101
The CRC16 /Buypass for this string is 06 35
i have 2 examples :
Java:
Java implementation
public class CRC {
private static final int CRC_POLYNOM = (int) 0x00008005;
private static final int CRC_MASK = (int) 0x00008000;
public static int CalculateCRC(byte[] buffer, int length) {
int crc = 0x00000000;
for (int i = 0; i < length; i++) {
crc ^= (int) ((buffer[i] << 8) & 0x0000FFFF);
for (int j = 0; j < 8; j++) {
if ((crc & CRC_MASK) == CRC_MASK) {
crc <<= 1;
crc = crc ^ CRC_POLYNOM;
} else {
crc <<= 1;
}
crc &= 0x0000FFFF;
}
}
return crc;
}
}
Code:
VB implementation
Public Function CRCCalculator(data() As Byte) As UShort
Dim crc As UShort = &H0&
Dim tmp As UShort = &H0&
Dim i As Long
Dim j As Long
For i = 0 To data.Length() – 1
tmp = data(i) * &H100&
crc = crc Xor tmp
For j = 0 To 7
If (crc And &H8000&) Then
crc = ((crc * 2) Xor &H8005&) And &HFFFF&
Else
crc = (crc * 2) And &HFFFF&
End If
Next j
Next i
CRCCalculator = crc And &HFFFF
End Function
I try this but i'm stuck :
Code:
LPARAMETERS tcString
LOCAL i, nbx, hlp
LOCAL crc as Byte
FOR i=1 TO LEN(tcString)
tmp=SUBSTR(tcstring,i,1) && CHR(0x1000) ...?
crc=BITXOR(crc,tmp)
FOR j=0 TO 7
IF BITAND(crc,0x8000) <> 0
crc=BITXOR(crc,0x8005)
ELSE
crc=BITAND(crc,0xffff)
ENDIF
ENDFOR
ENDFOR
RETURN TRANSFORM(crc,'@0x')
I have also other examples in C++
Thank you very much for help!