Expand|Select|Wrap|Line Numbers
- Option Explicit
- Dim i As Integer, j As Integer
- Dim bStatus As Boolean
- Dim cPacket(5) As Byte
- Dim nCRC As Long
- Private Sub Form_Load()
- cPacket(0) = &H1
- cPacket(1) = &H1
- cPacket(2) = &H1
- cPacket(3) = &H0
- cPacket(4) = &H0
- nCRC = &HFFFF
- For i = 0 To Ubound(cPacket)-1
- nCRC = nCRC Xor cPacket(i)
- For j = 0 To 7
- If ((nCRC And &H1) = True) Then
- nCRC = nCRC/2
- nCRC = nCRC Xor &H8408
- Else
- nCRC = nCRC/2
- End If
- Next j
- Next i
- Debug.Print nCRC
- End Sub
Expand|Select|Wrap|Line Numbers
- DWORD i,j;
- for(i=0;i<nLen;i++)
- {
- nCRC^=cPacket[i];
- for(j=0;j<8;j++)
- {
- if(nCRC & 0x0001)
- nCRC=(nCRC>>1) ^ 0x8408;
- else
- nCRC=(nCRC>>1);
- }
- }
- return nCRC;
data packet:01 01 01 00 00 or (0x01 0x01 0x01 0x00 0x00)
nCRC= 0x7DAB
data packet:01 00 00 00 00 or (0x01 0x00 0x00 0x00 0x00)
nCRC= 0x3BCC
But i dont know where is goes wrong....Hope anyone can help. Thanks!