Compute Binary Hash Code - CSharp System

CSharp examples for System:Byte

Description

Compute Binary Hash Code

Demo Code


using System.Diagnostics;
using System.Collections.Generic;

public class Main{
        internal static int ComputeBinaryHashCode(byte[] bytes)
        {//from w w w  .j av  a 2s  .  co  m
            Debug.Assert(bytes != null, "Byte array cannot be null");
            var hashCode = 0;
            for (int i = 0, n = Math.Min(bytes.Length, 7); i < n; i++)
            {
                hashCode = ((hashCode << 5) ^ bytes[i]);
            }
            return hashCode;
        }
}

Related Tutorials