Reputation: 3638
I'm trying to read in some bytes from a file in Java and then create bitmasks from some of the data and lengths and offsets from others.
I'm so close to getting my program working but I keep getting garbled data coming out the other end.
I'm 90% sure my problem is something to do with the way that Java is reading the bytes in.
There is some Python and C code that I'm basing my design on but I don't know how to convert this into Java. I've tried wrapping a byte[] in a byteBuffer but I'm still getting confusing results.
This is what I'm trying to get my head around:
bitmask:= copy inputBuffer[inputIndex] as 32-bit integer in little-endian format - needs to be four bytes
In C this is done as:
bitmask= (inputBuffer[inputIndex + 3] << 24) | (inputBuffer[inputIndex + 2] << 16) |
(inputBuffer[inputIndex + 1] << 8) | inputBuffer[inputIndex];
In Python this is: bitmask= unpack("<L", inputBuffer[inputIndex:inputIndex + 4])[0]
Until I can get this working correctly my program is falling over.
Can anyone offer any information on the best way of implementing this?
Many thanks
Tony
Upvotes: 1
Views: 209
Reputation: 12056
you can set ByteBuffer's byteOrder to littleEndian and just use getInt
Upvotes: 1