Sunday, 9 June 2019

Reversibly encode two large integers of different bit lengths into one integer

I want to encode two large integers of possibly different maximum bit lengths into a single integer. The first integer is signed (can be negative) whereas the second is unsigned (always non-negative). If the bit lengths are m and n respectively, the bit length of the returned integer should be less than or equal to m + n.

Just n (but not m) is known in advance and is fixed. The solution will as an example be used to combine a signed nanosecond timestamp of 61+ bits along with 256 bits of unsigned randomness to form a signed 317+ bit unique identifier.

I'm using the latest Python. There is a related preexisting question which addresses this in the special case when m == n.



from Reversibly encode two large integers of different bit lengths into one integer

No comments:

Post a Comment