Java uint32 (stored as long) to 4 byte array

Viewed 9430

I'm writing to a storage format that has uint32, with a max allowed value of "4294967295".

Integer in Java is, of course, just under half that at "2147483647". So internally, I have to use either Long or Guava's UnsignedInteger.

To write to this format, the byte array length needs to be 4, which fits Integer just fine, but converting Long to a byte array requires an array of length 8.

How can I convert a Long or UnsignedInteger representing a max value of "4294967295" as a 4 byte array?

3 Answers
Related