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

CSharp examples for System:Byte Array

Description

Returns the 16-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;/*w w w .  j a v a 2  s. c  o  m*/

public class Main{

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

Related Tutorials