I need to pack and unzip multiple values to / from one 64-bit value. I have 3 signed integers (x, y, z). I would like to pack them into one 64-bit value (signed or unsigned doesn't matter to me) using 24, 16 and 24 bits for the values respectively. Here are my requirements:
1) I can precede that the saved values do not exceed the limits of the number of bits that I use to save them in a 64-bit value, so no additional checks are required.
2) The initial values are signed, so I think some bit magic may be needed to ensure that nothing is lost.
3) This conversion will go through LOT, so it should be fast. I know that in C ++ it is quite easy to do this by storing the values in a structure that sets an integer length, and then sets a pointer that just points to the first value that can be used for a 64-bit value. With this method, there really is no math that needs to be done, all just reading memory or right. As far as I can tell, this is not so easy to do in C #, but C # is what I need to work with for this project.
4) I don’t care if the 64-bit value is signed or unsigned, if I can go in both directions using the operation and restore the initial values, and any type is used for the dictionary key.
source
share