Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode one Int64 back to two Int32?

Tags:

c#

Previous question was to encode two Int32 into one Int64 [C# - Making one Int64 from two Int32s

Question: How to decode one Int64 back to two Int32 ?

like image 974
mizi_sk Avatar asked Nov 20 '25 16:11

mizi_sk


1 Answers

Something like this:

long x = ...;

int a = (int) (x & 0xffffffffL);
int b = (int) (x >> 32);

It's just possible that the masking in the first form is unnecessary... I can never remember the details around narrowing conversions and signed values, which is why I've included it :)

like image 169
Jon Skeet Avatar answered Nov 23 '25 06:11

Jon Skeet