Returns the 32-bit sum of a range in a byte array. - CSharp System

CSharp examples for System:Byte Array

Description

Returns the 32-bit sum of a range in a byte array.

Demo Code


using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Reflection;
using System.Linq;
using System;//from  ww  w.j  a  v a2s  . c om

public class Main{
        /// <summary>
        /// Returns the 32-bit sum of a range in a byte array.
        /// </summary>
        public static Int32 GetInt32Checksum(this byte[] buffer, long offset, long length)
        {
            Int32 result = 0;
            for (long i = offset; i < offset + length; i++)
                result = unchecked((Int32)(result + buffer[i]));
            return result;
        }
}

Related Tutorials