I have well-defined binary data and I want to write a Java API for it.
The file format is similar to
File Signature char[4] 4 bytes
File Source ID unsigned short 2 bytes
Header Size unsigned long 4 bytes
Max double 8 bytes
I use DataInputStreamfor parsing data. charEasy to disassemble, no problem. But unsignedcan not be properly analyzed.
I know that Java does not have an unsigned number. How to convert it? (Please take unsigned long as an example).
EDIT
Here is the code I worte:
File file = new File("lidar.las");
DataInputStream in= new DataInputStream(new FileInputStream(file));
in.skipBytes(6);
long read = (long) (in.readInt() & 0xFFFFFFFFL);
System.out.println("read " + read);
exit
read 3288596480
my expected number is 1220 .I don't know the code that wrote this binary entry, possibly in c. All I want to do is write a Java version for reading data.
solvable
I'm not sure I can answer my own question. LOL
Anyway, here are the solutions.
private static int getSignedInt( final int unsignedInt ){
ByteBuffer bb=ByteBuffer.allocate(1024*4);
bb.putInt(unsignedInt).flip();
int result =bb.order(ByteOrder.LITTLE_ENDIAN).getInt();
bb.clear();
return result;
}