Game Development Reference
In-Depth Information
if ((crc32Value & 1) == 1)
{
crc32Value = (crc32Value >> 1) ^ polynomial;
}
else
{
crc32Value >>= 1;
}
}
_lookupTable[iterationIndex] = crc32Value;
}
}
}
}
You will notice the _lookupTable array variable and the static constructor; the
implementation precalculates the checksum values using the provided polynomial
and stores them in a lookup table to improve and speed up calculation performance.
After instantiation and the precalculation of the lookup table, you can call either
signature for the Calculate method. One version accepts a byte array containing
the data to generate the checksum for, and the other version accepts a
System.IO.Stream instead.
Usage
Using the functionality defined in the implementation class is fairly straightfor-
ward. The class will calculate the internal lookup table the first time you instantiate
it, and all you have to worry about is calling the Calculate() method. The Calculate
method is overloaded to accept either a byte array or a System.IO.Stream object.
The following code shows the proper way to use this class with a byte array:
byte[] data = new byte[DATA_SIZE];
Crc32 crc = new Crc32();
byte[] result = crc.Calculate(data);
The following code shows the proper way to use this class with a System.IO.Stream :
byte[] data = new byte[DATA_SIZE];
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(data))
{
Search Nedrilad ::




Custom Search