× Home (CS 211) Notes Projects Waxman's Website

Hexadecimal Number System

A hexadecimal numbering system uses 10 digits 0-9 and 6 letters A-F.
The letters represents numbers staring from 10 to 15.
A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
This is known as a base 16 number system.

Hexadecimal to Decimal

The first position (right most) in a hexadecimal number represents a 0 power of the base (16).
The last position (left most) in a hexadecimal number represents an x power of the base (16), where x represents the last position - 1.
(1A3)₁₆
= (1 x 16²) + (A x 16¹) + (3 x 16⁰)
= (1 x 16²) + (10 x 16¹) + (3 x 16⁰)
= (256) + (160) + (3)
= 419

(1A3)₁₆ = (419)₁₀

Adding Hexadecimals

In decimal addition (regular addition):
9 + 1 = 10

This is because when we added 1, we went past the highest possible value base 10 can hold in one digit, so we needed to carry over to the next digit.

In hexadecimal addition:

9 + 1 != 10

In hex, there is a letter that is used to represent 10, A.
So in hex, 9 + 1 = A

hex1

Example: What is 10 + 5 in hex?

Lets add 10 + 5 in regularly, 10 + 5 = 15.
BUT THAT'S NOT THE ANSWER, we are adding hexadecimal!!
In hex, the letter F represents 15. So 10 + 5 = F

Example: 8 + 9 = ? Remember this is hexadecimal addition and not decimal.


If we add 8 + 9 regularly we get 17. But hex cannot hold 17. Like when we added 9+1=10 in decimal, we exceeded the number it can hold in one bit. We need to carry over.
hex2Now just add the remaining columnhex2
So 8 + 9 = 11 in hex.
Notice how the answer is 12 and not C. That is because. We added 8 + 9, it went past C and had to go back beginning of the number line.

So now let look at adding a decimal (base 10) to hexadecimal (base 16)

(1A)₁₆ + (19)₁₀ = ?

  1. We CANNOT add it straight through like before. These are two different bases. So in order to add these two number. We need to convert one of the number. Let convert the base 10 to base 16.
  2. Converting to base 16 is simple. Simply take base 10 number and divide by 16 (integer division, no remainder). In this case, 19 / 16 = 1. This number is the leading number or the carry.
  3. Now take the base 10 number and mod it by 16. Mod is find the remainder. In this case 19 % 16 = 3. This our trailing number or sum.
  4. So (19)₁₀ = (13)₁₆
  5. Now we can add both number since they are both base 16.

(1A)₁₆ + (19)₁₀ = (1A)₁₆ + (13)₁₆ = 2D

Related: Pointers