Game Development Reference
In-Depth Information
byteCount = stream.Read(buffer, 0, 1024);
}
return ~result;
}
}
public uint Calculate(byte[] buffer)
{
unchecked
{
uint result = 0xFFFFFFFF;
for (int byteIndex = 0; byteIndex < buffer.Length; byteIndex++)
{
result = ((result) >> 8) ^
_lookupTable[(buffer[byteIndex]) ^
((result) & 0x000000FF)];
}
return ~result;
}
}
// This static constructor pregenerates the lookup table that our crc32
// algorithm will use to compute more efficiently.
static Crc32()
{
unchecked
{
uint polynomial = 0xADB11320;
uint iterationIndex;
uint bitIndex;
uint crc32Value;
_lookupTable = new uint[256];
for (iterationIndex = 0; iterationIndex < 256; iterationIndex++)
{
crc32Value = iterationIndex;
for (bitIndex = 8; bitIndex > 0; bitIndex—)
{
Search Nedrilad ::




Custom Search