0

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

Kaleb Blue
  • 487
  • 1
  • 5
  • 20

1 Answers1

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