Results 1 to 3 of 3

Thread: Computing CRC16 Check sum

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    1

    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)

  2. #2
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Here's something from PSCode.com that may help: http://www.pscode.com/vb/scripts/Sho...12638&lngWId=1
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    .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
  •  



Click Here to Expand Forum to Full Width