With the "remainder" operator, spelled Mod
in Visual Basic:
offset Mod &H10000
Question
I'm working on a specialty hexadecimal editor that includes a Z80 two-byte pointer converter.
The mathematics behind the conversion are like so:
&H4000
- &H7FFF
, it must be converted like this: (offset % &H4000) + &H4000
. In other words:
&H0000
to &H3FFF
, add &H4000
to the offset.&H4000
to &H7FFF
, do not do anything to the offset.&H8000
to &HBFFF
, subtract &H4000
from the offset.&HC000
to &HFFFF
, subtract &H8000
from the offset.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)?
Solution
With the "remainder" operator, spelled Mod
in Visual Basic:
offset Mod &H10000
OTHER TIPS
The answer using the 'Mod' operator is correct.
But, to be pedantic, this is a 'modulus' operator, and not a 'remainder' operator. There is a difference for negative numbers. (I appreciate we are not talking about negative numbers here.)