1

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

3
  • Please post the Java code you're trying to use. Commented Jan 23, 2011 at 13:56
  • I've put a bit of the code here mrthaggar.com/partialCode.txt Apologies for it being a bit messy, I hope you can understand what I'm trying to do from it!! Commented Jan 23, 2011 at 15:19
  • @user583240: Please add the Java code you're trying to use to this question. Please add the exact part that's supposed to match the Python and C parts. Please update the question. Commented Jan 23, 2011 at 18:08

1 Answer 1

1

you can set ByteBuffer's byteOrder to littleEndian and just use getInt

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.