LESSON 04 –
HEXADECIMAL (BASE 16)

 

 

LESSON NOTE

WHAT IS HEX?

 

Hex is short for hexadecimal, which is the name we give to the base 16 number system. 

 

Hex has 16 symbols: 0 to 9 and A to F. 

 

COUNTING IN HEX

 

Counting in hex is fairly simple.  The value that we normally call ten is written as A.  Eleven is B.  Twelve, thirteen, fourteen and fifteen are C, D, E and F.

 

Decimal

Hex

0

0

1

1

2

2

3

3

4

4

5

5

6

6

7

7

8

8

9

9

10

A

11

B

12

C

13

D

14

E

15

F

 

WHY IS HEX POPULAR?

 

Hex is popular because it can be used as a convenient representation of binary.  It turns out that four digits in binary can be replaced by 1 digit in hex.  This makes converting between binary and hex extremely easy.

 

COMPARING BINARY AND HEX

 

Look at the table below.  Notice that at the end of the table, both hex and binary would have to add a new digit.  Because of this, we can always swap four binary digits for one hex digit.

 

 

Hex

Binary

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

8

1000

9

1001

A

1010

B

1011

C

1100

D

1101

E

1110

F

1111

 

 

CONVERTING HEX TO BINARY

 

To convert, we simply replace each hex digit with the four corresponding binary digits.  The table above is a helpful guide.

 

Examples

 

            2A = 0010 1010

 

            AB11 = 1010 1011 0001 0001

 

            32C = 0011 0010 1100

 

            110 = 0001 0001 0000

 

CONVERTING BINARY TO HEX

 

To convert, we simply replace each sequence of four binary digits by the corresponding hex digit.  It may be necessary to add zeros at the beginning of the number to make sure that the number has a proper number of bits.

 

Examples

 

            0011 = 3

 

            1111 0010 = F2

 

            1001 1100 = 9C

           

            111 = 0111 (after adding leading zero) = 7

 

            11 0010 = 0011 0010 (after adding two leading zeros) = 32

 

SO WHY ISN’T DECIMAL THAT EASY TO CONVERT?

 

The location where decimal needs a new digit does not match up with the location where binary needs a new digit.  Therefore, each decimal digit cannot be associated to specific number of bits.

 

Decimal

Binary

0

0000

1

0001

2

0010

3

0011

4

0100

5

0101

6

0110

7

0111

8

1000

9

1001

?

1010

?

1011

?

1100

?

1101

?

1110

?

1111