CRC table caluclation problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas Håkansson

    #1

    CRC table caluclation problems

    Hi,

    I'm trying to implement a 32bit Table based CRC caluclator based on the
    guidelines in this
    http://thorkildsen.no/faqsys/docs/crc.txt document. However I have run into
    a small
    "problem" that's made me think. When I create my CRC class I want to
    precalculate the
    crc table and acording to the document I should get the MSB of the byte in
    question, check
    if it is a 1 and if so XOR the byte, if not continue. Obviously I need to
    keep shifting the byte
    to the left to keep getting the "MSB" but when I shift left I get obvious
    wrong precalculated
    values, but when I shift right and mask the LSB bit I get what appears to be
    valid
    precaluclated values.

    Could anyone explain WHY i should shift right and keep checkin the LSB when
    the docs
    claim to shift left and check the MSB ?

    Here is the code I'm working on.

    NOTE: this.poly is of type uint and this.table is a uint[256] array

    public class CRC
    {
    private uint poly;
    private uint[] table;

    public CRC(uint poly)
    {
    this.poly = poly;
    this.table = new uint[256];
    uint indexValue = 0;

    for(int index=0; index<256; index++)
    {
    indexValue = (uint)index;
    for(int bit=7; bit>=0; bit--)
    {
    // THIS WORKS
    if( (indexValue & 0x0000001) == 1 )
    indexValue = (uint)((indexVa lue >> 1) ^ this.poly);
    else
    indexValue = (uint)(indexVal ue >> 1);

    // THIS GIVES STRANGE VALUES
    // if( (indexValue & 0x1000000) == 1 )
    // indexValue = (uint)((indexVa lue << 1) ^
    this.poly);
    //else
    // indexValue = (uint)(indexVal ue << 1);
    }
    this.table[index] = indexValue;
    Console.WriteLi ne(String.Forma t("{0:X8}",
    this.table[index]));
    }
    }
    }

    --
    ANDREAS HÅKANSSON
    STUDENT OF SOFTWARE ENGINEERING
    andreas (at) selfinflicted.o rg


Working...