# Hexadecimal Arithmetic

This article is part of a series, access the series index.

### Calculating Hexadecimal

I’ve shown you how to perform the four functions of arithmetic using binary, but I have not shown you how to perform the two most important, or at least the two most used, operations in hexadecimal and octal (next tutorial). I’m not really showing you anything you don’t already know, the difference only lies in the fact that you may not know it in hexadecimal or octal (next tutorial).

### Hexadecimal Addition

First off, to do addition in hexadecimal it helps for us to remember our number line:

1 |
0 1 2 3 4 5 6 7 8 9 A B C D E F |

With that number line it’s easy to see how hexadecimal addition works. For example, 5 + 5:

1 2 3 |
5 + 5 0 1 2 3 4 5 6 7 8 9 A B C D E F A |

So 5 + 5 = A; A in this case is what we would refer to as 10 in decimal. Since this is hexadecimal we can go up to 15 before filling up the ‘sixteens place’. For a refresher on number bases refer to the binary article.

Here are some more example hexadecimal additions:

1 2 3 4 |
1 4 7 9 + 1 + 8 + 8 + 9 --- --- --- --- 2 C F 12 |

Whoah, whoah, where’d that 1 come from on the 9 + 9? And… 12? Remember, this is hexadecimal. When you get to the value 16 and above you ‘carry’. Observe:

1 2 3 4 |
F + F --- 1E |

Notice how it’s 1E, and not 1F. That’s exactly how 9 + 9 is equal to 18 in decimal, not 19. If you are having trouble wrapping your head around that, just think about for a moment, or lay two number lines out next to each other and count from one F to the next E. Remember that F is equal to 15 in hexadecimal. Then things should make more sense.

### Hexadecimal Subtraction

First off, to do subtraction in hexadecimal we shall once again remember our number line:

1 |
0 1 2 3 4 5 6 7 8 9 A B C D E F |

Now, we count backwards in our calculations:

1 2 3 4 |
F E F - 1 - 5 - F --- --- --- E 9 0 |

But what about carrying? What if subtract 1 from 10 in hexadecimal? You have to remember that 10 = 16 in decimal. It’s useful to think of 10 (16) as one solid value while carrying and not as two digits put together. You do the same thing when carrying in decimal. You cross out a number, subtract one, and then add a ‘ten’ (10) to the next placevalue. Here’s an example in hexadecimal:

1 2 3 4 |
10 21 - F - F ---- ---- 1 12 |

10 (16) – F (15) = 1 (1) Pretty exciting huh? More exciting is how 21 – F = 12. Since F is greater than 1 we have to carry from the ‘sixteen’s’ place. We subtract 1 from 2, and add a ‘sixteen’ to the one’s place making it 11 (17 decimal). 11 – F is 2, to double check convert it to decimal 11 (17) – F (15) = 2. Then we take down the modified sixteen’s place, a 1, and we get 12 (18).

### Conclusion

We’ll cover octal arithmetic in another article. For now, this should have you calculating hexadecimal ’til the cows come home. This is an important skill when calculating addresses in memory. Memory locations are often referred to in hexadecimal in order to shorten their length. Hope this has helped you learn some more about computers!

If you appreciate my tutorials please help support me through my Patreon.

photo credit: Hexadecimal Time via photopin (license)