Calculate bytes between two hex offsets
<p>In Python, I'm trying to extract some data from a binary file. I know the offsets of my data. They are always the same. For instance, written beneath is the first 4 offsets and the converted offset as a decimal value.</p>

<ul>
<li>Offset1 - 0x00000409 - 1033</li>
<li>Offset2 - 0x0000103A - 4154</li>
<li>Offset3 - 0x00001C6B - 7275</li>
<li>Offset4 - 0x0000289C - 10396</li>
</ul>

<p>I know that each offset (after the first one), is 3121 decimals apart, so is there a way I can just skip to the next offset? How do I move 3121 decimals to the next offset?</p>

<p>There are 128 offsets that I need to extract. I hope there is a way of dynamically determining the difference (number of bytes) between offsets?</p>

<p>I can then get the same data each time, using 0x100 to extract 256 characters from the offset.</p>

<p>use <code>file.seek()</code> to skip between locations in a file. In this case, to go to the next location in the file, you would use <code>file.seek(3121, 1)</code> which seeks 3121 bytes ahead relative to the current position.</p>

<p>EDIT: I didn't realize you were changing the file position after opening it, so it should actually be 2685 bytes that you're seeking ahead each time, to account for the 256 you read.</p>

python binary hex offset bytecode