I'm playing around with FNV-1a hashing. I have a very simple implementation, which seems to work very well for 32 bit hashes and 64 bit hashes:
const ulong FNV_PRIME = 0x00000100000001B3;
const ulong FNV_OFFSETBASIS = 0xCBF29CE484222325;
ulong hash = FNV_OFFSETBASIS;
var fileContents = File.ReadAllBytes(@"D:\Some.iso");
foreach(var b in fileContents){
hash ^= b;
hash *= FNV_PRIME;
}
Console.WriteLine(hash);
Console.WriteLine(BitConverter.GetBytes(hash));
For the 32-bit hash, I used uint (32 bit integer). For the 64 bit hash, I'm using ulong (64 bit integer).
Now, I'd like to try the 128-bit variant. C# however, does not have a 128-bit integer type. Or does it? The .NET documentation for System.Guid clearly states (under "Remarks"):
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks
So, why are they stating that it is a 128-bit integer? Can I do arithmetics on the type? I've tried, but I cannot seem to assign a number (such as the initial offset) to a type of System.Guid. I can't say that I'm that surprised, but I'm wondering why it is so clearly stated this is a "128-bit integer".
(One of the possible solutions for the original problem is obviously to use the System.Numerics.BigInteger library. I just came across this during my search and was wondering about the statement on MSDN).