If I have an application, Ryno, that produces unique increasing long numbers. I have another application, Cyan,that sends a message and needs a unique integer id. I would want to use the number from Ryno as the id for message in Cyan. Is there a way to encode long to int. Cyan will not send no more than 1 billion messages
Asked
Active
Viewed 68 times
0
-
Not sure what will happen in lonValue > Integer.MAX_VALUE – Kaleb Blue Mar 27 '20 at 14:41
1 Answers
0
It works just fine
long f = 10292029202924l;
System.out.println(f);
int v = (int)f;
System.out.println(v);
System.out.println((f & xFFFFFFFF);
prints
10292029202924
1287561708
1287561708
f = -1L;
v = (int)f;
System.out.println(v);
v = (int)(f & 0x7FFFFFFF); // mask off sign extension
System.out.println(v);
prints
-1
2147483647

WJS
- 36,363
- 4
- 24
- 39