|
-
Mar 25th, 2004, 08:33 AM
#1
Thread Starter
New Member
Computing CRC16 Check sum
Working with RFID software. Requires cal. CRC 16 check sum:
I don't think my VB code is cal. correctly
This is the C code provided by the vendor.
unsigned int CRC_CHECK(unsigned char*ary, unsigned char len)
{
unsigned int crc;
unsigned charij;
crc=0xffff;
for (i=0;i<len;i++,ary++)
{
crc=((unsigned int)*ary<<8)^crc;
for (j=0;j<8;j++)
{
if (crc & 0x8000)
crc=(crc<<1)^0x1021;
else
crc<<=1;
}
}
return(crc^0xffff);
}
In 0x05, 0x00, 0x00
Out 0xD8, 0x93
What would the VB code look like? This is what I tried:
Public Function CRC16A(Buffer() As Byte) As Long
Dim i As Long
Dim Temp As Long
Dim CRC As Long
Dim J As Integer
For i = 0 To UBound(Buffer) - 1
Temp = Buffer(i) '* &H100&
CRC = CRC Xor Temp
For J = 0 To 7
If (CRC And &H8000&) Then
CRC = ((CRC * 2) Xor &H1021&) And &HFFFF&
Else
CRC = (CRC * 2) And &HFFFF&
End If
Next J
Next i
CRC16A = CRC Xor &HFFFF&
End Function
Dim CRC As clsCRC16
Dim Buffer1(2) As Byte
Dim Ret As Long
Debug.Print "**"
Set CRC = New clsCRC16
Buffer1(0) = Hex$(5)
Buffer1(1) = Hex$(0)
Buffer1(2) = Hex$(0)
Ret = CRC.CRC16A(Buffer1)
-
Mar 29th, 2004, 11:30 PM
#2
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Apr 10th, 2004, 12:56 PM
#3
.net has some bullet proof hashing stuff under system.security namespace.
Dead good!
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|