Skip to content

Instantly share code, notes, and snippets.

@rasmuskl
Created September 26, 2012 07:39
Show Gist options
  • Save rasmuskl/3786618 to your computer and use it in GitHub Desktop.
Save rasmuskl/3786618 to your computer and use it in GitHub Desktop.
FNV 1a 64-bit C# non-cryptographic hash
// FNV-1a (64-bit) non-cryptographic hash function.
// Adapted from: http://github.com/jakedouglas/fnv-java
public ulong HashFNV1a(byte[] bytes)
{
const ulong fnv64Offset = 14695981039346656037;
const ulong fnv64Prime = 0x100000001b3;
ulong hash = fnv64Offset;
for (var i = 0; i < bytes.Length; i++)
{
hash = hash ^ bytes[i];
hash *= fnv64Prime;
}
return hash;
}
@rasmuskl
Copy link
Author

@hamarb123 Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment