PNGMask.PNG.CRC32 C# (CSharp) Method

CRC32() public static method

public static CRC32 ( byte stream, int offset, int length, uint crc, uint &crcTable ) : uint
stream byte
offset int
length int
crc uint
crcTable uint
return uint
        public static uint CRC32(byte[] stream, int offset, int length, uint crc, ref uint[] crcTable)
        {
            uint c;
            if (crcTable == null)
            {
                crcTable = new uint[256];
                for (uint n = 0; n <= 255; n++)
                {
                    c = n;
                    for (var k = 0; k <= 7; k++)
                    {
                        if ((c & 1) == 1)
                            c = 0xEDB88320 ^ ((c >> 1) & 0x7FFFFFFF);
                        else
                            c = ((c >> 1) & 0x7FFFFFFF);
                    }
                    crcTable[n] = c;
                }
            }
            c = crc ^ 0xffffffff;
            var endOffset = offset + length;
            for (var i = offset; i < endOffset; i++)
            {
                c = crcTable[(c ^ stream[i]) & 255] ^ ((c >> 8) & 0xFFFFFF);
            }
            return c ^ 0xffffffff;
        }