Consider I\'ve two numbers 1023232 & 44. I want to generate a unique number representing this combination of numbers. How can i generate it?
Requirement
If you can represent it as a string, this should work:
Hash((int1 | int2).ToString());
Like so:
public static string Hash(string plaintext)
{
var hashAlgorithm = new SHA1CryptoServiceProvider();
var unhashedBuffer = Encoding.Default.GetBytes(plaintext);
var hashedBuffer = hashAlgorithm.ComputeHash(unhashedBuffer);
return Convert.ToBase64String(hashedBuffer);
)
If X & Y are Int add a seperator. Always unique.
X = 100, Y = 5 => 100.5
X = 1023232, Y = 44 => 1023232.44
If you are using ints and don't mind the result being a long, this should work:
Math.Max(x, y) << 32 | Math.Min(x, y)
The fact that the numbers are stored in the high and low dwords of the result get you your uniqueness constraint.
The fact that the higher number is always in the high dword gets you the symmetry you wanted.