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
&H0000
to&H3FFF
, add&H4000
to the offset. - If the offset is from
&H4000
to&H7FFF
, do not do anything to the offset. - If the offset is from
&H8000
to&HBFFF
, subtract&H4000
from the offset. - If the offset is from
&HC000
to&HFFFF
, subtract&H8000
from 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)?