0

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?

Jim
  • 717

2 Answers2

2

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$$

Amzoti
  • 56,093
  • Good work! Keeps you sharp ;-) (+) – amWhy Sep 23 '13 at 00:06
  • This makes the second position a 16. How can this hold? The digits are only 0-F so how can the second position be 16? – Jim Sep 23 '13 at 05:17
  • How does a digit move to the next state? You go from 15 to 16. When you go back, you bring all 16 with you. Clear? You are borrowing a 16 from the left digit. Remember, each bit in hex represent $16$. – Amzoti Sep 23 '13 at 05:24
  • Write out $16^3 | 16^2 | 16^1 | 16^0$. What happens if you take the $16^1$ bit and move it right? – Amzoti Sep 23 '13 at 05:31
0

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.