Skip to main content

# Welcome to CS

## Section4.11Hexadecimal

Hexadecimal is base 16. Much like base 10 uses digits that represent powers of 10 and binary uses digits that represent powers of 2, hexadecimal uses digits that represent powers of 16. Here is how we would interpret $${2047}_{16}\text{:}$$
So $${2047}_{16}$$ = 2 * 4096 + 0 * 256 + 4 * 16 + 7 * 1 = $${8263}_{10}\text{.}$$
Using this scheme, $${10}_{16}$$ = 1 * 16 + 0 * 1 = $${16}_{10}\text{.}$$ Which raises the question “How do we represent ten in hexadecimal?” A 1 in the second column indicates a 16, so we can’t use that - we have to fit all the values up to 15 in the first column. We do so by using the letters A-F to indicate 9-15:
Thus in the hexadecimal number $${\textrm{1EA}}_{16}$$ the E means 14 copies of the second digit (16). The A means 10 copies of the rightmost digit (1):
So $${1\textrm{EA}}_{16}$$ = 1 * 256 + 14 * 16 + 10 * 1 = $${490}_{10}$$ .

### Subsection4.11.1Hexadecimal Conversion To and From Binary

In hexadecimal, each digit can represent 16 different values: 0-F (0-15). In binary, we can represent the same number of values using 4 bits: 0000-1111 (0-15). What that means, is that each hex digit represents the same information as four binary digits - there is a direct mapping between a hex digit and a four-bit pattern:
To convert binary to hex, simply break up the number into groups of 4 digits and convert each group, as in this example (the binary and hexadecimal numerals are both equivalent to decimal 1731).
 011011000011 0110 1100 0011 6 C 3 6C3
To convert hex to binary, we can just turn each hex digit into one group of four binary digits, as in this example (the hexadecimal and binary numerals are both equivalent to decimal 161).
 A1 A 1 1010 0001 10100001
This video reviews how hexadecimal works and provides a few more examples:
Closed Caption Version
1
https://smartplayer.captionsync.com/play.php?vid=1521238137sagefreeman_0903e4b5d163

### Subsection4.11.2Why Hexadecimal?

Why would we want another base system? Large binary values are hard for people to read accurately and remember. Try it yourself - quickly try to decide if 0011100101110110 and 0011100101100110 are the same.
Those two binary strings look like this in hex: $${3976}_{16}$$ and $${3966}_{16}\text{.}$$ In that format, it is a little easier to say the values and to see where the difference is, isn’t it? Because changing switching from binary to hex is so easy, hexadecimal is used to display binary values in a more human-readable form. You will see an example of where this is used in web page design on the next page.

### Checkpoint4.11.5.

What decimal value does the hexadecimal number 2A represent?

### Checkpoint4.11.6.

What does hexadecimal 3FC look like in binary?
You have attempted of activities on this page.