Ionic.Crc.CRC32.UpdateCRC C# (CSharp) Method

UpdateCRC() public method

Process one byte in the CRC.
public UpdateCRC ( byte b ) : void
b byte the byte to include into the CRC .
return void
        public void UpdateCRC(byte b)
        {
            if (this.reverseBits)
            {
                UInt32 temp = (_register >> 24) ^ b;
                _register = (_register << 8) ^ crc32Table[temp];
            }
            else
            {
                UInt32 temp = (_register & 0x000000FF) ^ b;
                _register = (_register >> 8) ^ crc32Table[temp];
            }
        }

Same methods

CRC32::UpdateCRC ( byte b, int n ) : void

Usage Example

コード例 #1
0
        private static void convertDataTrunk(PngihdrTrunk ihdrTrunk, byte[] conversionBuffer, int nMaxInflateBuffer)
        {
            if (conversionBuffer == null) throw new ArgumentNullException("conversionBuffer");
            inflate(out conversionBuffer);

            // Switch the color
            int nIndex = 0;
            for (int y = 0; y < ihdrTrunk.MnHeight; y++)
            {
                nIndex++;
                for (int x = 0; x < ihdrTrunk.MnWidth; x++)
                {
                    byte nTemp = conversionBuffer[nIndex];
                    conversionBuffer[nIndex] = conversionBuffer[nIndex + 2];
                    conversionBuffer[nIndex + 2] = nTemp;
                    nIndex += 4;
                }
            }

            ZlibCodec deflater = deflate(conversionBuffer, nMaxInflateBuffer);

            // Put the result in the first IDAT chunk (the only one to be written out)
            PngTrunk firstDataTrunk = getTrunk("IDAT");

            var crc32 = new CRC32();
            foreach (byte b in System.Text.Encoding.UTF8.GetBytes(firstDataTrunk.getName()))
            {
                crc32.UpdateCRC(b);
            }
                crc32.UpdateCRC((byte)deflater.NextOut,(int)deflater.TotalBytesOut);
            long lCrcValue = crc32.Crc32Result;

            firstDataTrunk.MnData = deflater.OutputBuffer;
            firstDataTrunk.MnCrc[0] = (byte) ((lCrcValue & 0xFF000000) >> 24);
            firstDataTrunk.MnCrc[1] = (byte) ((lCrcValue & 0xFF0000) >> 16);
            firstDataTrunk.MnCrc[2] = (byte) ((lCrcValue & 0xFF00) >> 8);
            firstDataTrunk.MnCrc[3] = (byte) (lCrcValue & 0xFF);
            firstDataTrunk.MnSize = (int) deflater.TotalBytesOut;
        }