Hexadecimal Representation

Hexadecimal Representation

Binary is the heart of computing. It is not the easiest method for humans to work with. Working with base-10 numbers is great for humans, but it doesn’t replicate how a computer works very well. Figuring out what Two’s Complement or overflow means in base-10 is not obvious. Hexadecimal is a representation that can makes human work easier and still convey how the computer works.

A 4-bit value can represent numbers from 0 to 15. Hexadecimal is a base-16 number system. Each digit represents 4-bits on a computer. The digits are shown in the table below.

Hexadecimal Digit

Base-10

4-bit Binary

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

A

10

1010

B

11

1011

C

12

1100

D

13

1101

E

14

1110

F

15

1111

Since each digit exactly matches 4 bits, the mapping between hexadecimal and binary is trivial.

Just like in binary, the addition of two digits can produce a carry. In this case, we carry on \(16_{10}=10_{16}\). If we add \(14_{10}+9_{10}=23_{10}\) in hexadecimal it looks like \(E_{16}+9_{16}=17_{16}\).

We can also convert back to base-10.

\( \begin{align} 17_{16} =& 1*16^{1} + 7*16^{0} \\ =& 16 + 7 \\ =& 23_{10} \end{align} \)

Addition and multiplication follow all the same rules we saw for other bases. Since the base is so closely related to binary, when a digit overflows in hexadecimal that tells us where a bit overflow would take place in binary. We can even easily use Two’s Complement and deal with the overflow bits just like in binary.

We can use the column method to add hexadecimal numbers. The computation of \(175_{10}+23_{10}=198_{10}\) is shown in hexadecimal below.

\( \begin{align} & 10 & \text{(Carry)} \\ & AF & \text{(Value 1)} \\ +& 17 & \text{(Value 2)} \\ & = & \\ & C6 & \text{(Result)} \\ \end{align} \)

Hexadecimal gives us a more compact method to write and display binary numbers. We will use hexadecimal when looking at raw computer code. Displaying the values in binary would take up far to much space. Using base-10 would make it to hard to follow how the binary works. Hexadecimal provides a useful middle ground.