I'm working on a specialty hexadecimal editor that includes a Z80 two-byte pointer converter.
The mathematics behind the conversion are like so:
- Take the offset that you wish to point to.
- Take the last four digits of the offset, and cut off the rest.
- If the offset is outside the range
&H4000-&H7FFF, it must be converted like this:(offset % &H4000) + &H4000. In other words:- If the offset is from
&H0000to&H3FFF, add&H4000to the offset. - If the offset is from
&H4000to&H7FFF, do not do anything to the offset. - If the offset is from
&H8000to&HBFFF, subtract&H4000from the offset. - If the offset is from
&HC000to&HFFFF, subtract&H8000from the offset.
- If the offset is from
My problem is I don't know how I could turn a 5 or 6-digit hex offset into a two-digit offset. How would I shave off the extra bytes at the beginning (step two)?