You can receive the unsigned long as long
, as "long" as one does not calculate with the long. You can even display that long as unsigned using Long.toUnsignedString(n)
.
Otherwise store it in a BigInteger
. Ideally loaded as 8 big-endian bytes.
// Some snippets, unordered, showing useful constructs.
long n = ...;
n = Long.reverseBytes();
byte[] bigendian = new byte[8];
ByteBuffer buf = ByteBuffer.wrap(bigendian); // .order(ByteOrder.LITTLE_ENDIAN);
buf.putLong(n);
// Creating a BigInteger from unsigned long's bytes, requiring big-endian order.
BigInteger num = new BigInteger(1, bigendian); // 1 = positive