Java - read bytes at a given offset
I am having a little trouble understanding how I can read and return the value of a specific offset position in a file.
For example, from my hex editor, I know the offset is D768 and the value is 32 bits. So how can this value be read and displayed in the label.
Any help would be generally appreciated.
+3
source to share
4 answers
Use skipBytes
to jump to a preset position. To read a 32 bit number, you can use DataInputStream
if value is big-endian. If it's a bit, you need to manually convert four bytes to int
:
int value = (int)bytes[0]
| ((int)bytes[1] << 8)
| ((int)bytes[2] << 16)
| ((int)bytes[3] << 24);
+1
source to share