0

I have some data which I'm reading from a Binary File, I see that the data is of unsigned type. How can I read the file in Java to convert it correctly? Right now I'm having to do

 byte[] bdata = new byte[DataLen];
 Integer.reverseBytes(ByteBuffer.wrap(bdata).getInt(0)) & (-1L >>> 32)

to get the data correctly. Is there a easier way to do it ?

allthenutsandbolts
  • 1,513
  • 1
  • 13
  • 34

1 Answers1

-1

there is no unsigned integer in java, but there is long, which can hold whole unsigned integer. You can convert between long, and bytes How do I convert Long to byte[] and back in java

mlecz
  • 985
  • 11
  • 19
  • I feel like this was not actually OPs question. They have to read a file that contains an unsigned type, maybe written by another program. And want to be able to read it correctly. Which is a job for `ByteBuffer`, as explained in the linked duplicate. – Zabuzard Jul 14 '22 at 17:30