Reputation: 3357
My Code
ByteBuffer bb = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
bb.getDouble())
I am trying to pass Uint24 containing 2 bytes into a variable using above code. But it crashes giving me error
java.lang.IndexOutOfBoundsException: index=3 out of bounds (limit=6, nb=4)
For single byte I am using short like bb.getShort();
Please someone could explain me on how to do it.
Upvotes: 2
Views: 1774
Reputation: 760
Let's note: the getDouble() tries to read eight bytes at the current index, so perhaps there aren't so much data in the array (limit=6).
I think we should use the asIntBuffer() (https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#asIntBuffer()) in yours case.
Bests )
Upvotes: 0