Confused in basic hex subtraction
I am having trouble thinking in hex terms when making hex subtraction.
Example: I am trying to do: 0x503c - 0x40
I am stuck in the part subtracting the 4 from 3. I understand that since in the next position we have 0 we must "borrow" from the 5 i.e. removing a 16^3 (leaving 4 as the first digit) but I am stuck on how to distribute this 16^3 to the next 2 figures so as to do the subtraction.
In decimal e.g. the 100 borrowed would be a 90 and a 10 (ever the decimal and digit column) but I am confused with the hex arithmetic.
Any help?
2 Answers
$\begingroup$Recall, in hex, you are borrowing groups of $16_{10}$.
So, we have:
$$0x503C - 0x40$$
- We can subtract $0$ from $C$ = $C$
- We need to borrow, so we borrow a $16$ from $5$, making that position a $4$. This makes the second position a $16$, but we need to borrow $1$ from it, leaving $F$.
- We needed and borrowed a 16 for the third position, so now have $16 + 3 - 4 = 15 = F$.
Writing the result yields:
$$0x503C - 0x40 = 0x 4FFC$$
$\endgroup$ 4 $\begingroup$To subtract 0x0040 from 0x503C:
$C-0=C$
$3-4=F$, borrow one
$0-(0+\color{red}1)=F$, borrow one
$5-(0+\color{red}1)=4$.
Done: 0x4FFC. The method is really the same as with decimal notation.