I am struggling to unpack my data from a long type to two numbers. Not sure where i am going wrong.
I create a unique number from two numbers by packing them into a long:
public static long Squeeze(float x, float y)
{
return ((long)x << 32) | (long)y;
}
So the long consists for 4 bytes for x then 4 bytes for y.
Then i am trying to get the numbers back out with:
float x = (float)(hash >> 32);
float y = (float)(hash | int.MaxValue); // this should be 1111 1111 1111 1111 i think
But it doesn't seem to work, x
appears to be correct, but y
is giving me numbers that it should not.
Also it needs to work for negative numbers too.
Example:
(2.0, 9.0) => Packed: 8589934601 => Unpacked: (2, 1.073742E+10)
(-1.0, -1.0) => Packed: -1 => Unpacked: (-1.0, -2147484000.0)