Compute Hash for byte array - CSharp System

CSharp examples for System:Byte Array

Description

Compute Hash for byte array

Demo Code


using System.Collections.Generic;
using System;//from  w w w. jav  a  2  s.c o m

public class Main{
    public static int ComputeHash( this byte[] data )
      {
         // http://stackoverflow.com/a/468084/126995
         unchecked
         {
            const int p = 16777619;
            int hash = (int)2166136261;

            for( int i = 0; i < data.Length; i++ )
               hash = ( hash ^ data[ i ] ) * p;

            hash += hash << 13;
            hash ^= hash >> 7;
            hash += hash << 3;
            hash ^= hash >> 17;
            hash += hash << 5;
            return hash;
         }
      }
}

Related Tutorials