Hexadecimal Representation
- EK 2.1.1C At a higher level, bits are grouped to represent abstractions, including but not limited to numbers, characters, and color.
- EK 2.1.1D Number bases, including binary, decimal, and hexadecimal, are used to represent and investigate digital data.
- EK 2.1.1F Hexadecimal (base 16) is used to represent digital data because hexadecimal representation uses fewer digits than binary.
This page has a lot of commented out text that should be read over and removed or moved. --MF, 12/18/17
Typing long strings of ones and zeros is inconvenient and prone to error. A more efficient method is to use hexadecimal (base 16). One hex digit represents any whole number between 0 an 15. So eight digits of binary can be translated into two digits of hexadecimal, which is much easier and much less error-prone for humans.
Mary should fix up the CSS in these tables some day. --MF, 12/18/17
Eight bits in base two... | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | ||||
128s place | 64s place | 32s place | 16s place | eights place | fours place | twos place | ones place | ||||
...is two digits in base 16. | |||||||||||
161 | 160 | ||||||||||
sixteens place | ones place |
For example: 12110 = 011110012 = 7916 | |||||||
---|---|---|---|---|---|---|---|
0 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
7 | 9 |
Place value notation uses only one digit in each place. We need to represent 0 through 15, and we have digits for 0-9, so we choose A-F for the remaining values:
10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|
A | B | C | D | E | F |
Mary, you reduced this katex with a style tag (not proper CSS) because you couldn't figure out how to make it work with CSS. Fix this later. --MF, 12/18/17
This stands for 3 \times 256 + 11\times 16 +7\times 1 or 951.
- Watch this Hexadecimal and Binary Timer Snap! program run. The top row counts in binary, the middle in decimal, the bottom in hex. Write a description of the hex counter's behavior.
Reading Hexadecimal
Base 16 uses powers of sixteen instead of powers of two or ten. Place values in hexadecimal represent the units place (160 = 1), the sixteens place (161 = 16), the two hundred fifty-sixes place (162 = 256), the four thousand ninety-sixes place (163 = 4096), etc. So, for example:
3B16 = 3 × 161 + 11 × 160 = 48 + 11 = 5910
To translate from hexadecimal (for example, 7B316) to base 10, first, write the digits on paper. Then write out the hexadecimal place values: start at the right with 1, then write 16 in the next place to the left, then write 256 (which is 162), and so on. Each new place will be worth 16 times the one to its right.
Remember: A-F cover the digits after 9:
10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|
A | B | C | D | E | F |
7 | B | 3 |
---|---|---|
256 | 16 | 1 |
So, 7B316 = (7 × 256) + (11 × 16) + (3 × 1) = 1792 + 176 + 3 = 197110.
- Translate these hexadecimal numerals into base 10 notation:
- AF16
- 5D16
- 1816
- 3E816
A numeral such as 11 means eleven in the usual decimal notation, or three if it is a binary numeral, or seventeen in hexadecimal notation. The only way you know that the "18" in part (c) above doesn't mean eighteen is that subscript "16" means hexadecimal.
FF16
= (15 × 161 + 15 × 160)10
= (15 × 16 + 15)10
= 25510
Writing Hexadecimal
To translate from base 10 (for example, 29910) to base 16, first write out the hexadecimal place values by multiplying by 16 moving left from the units place until you get to a value larger than your number (4096 for this example). Then think, "My number is smaller than 4096, so I leave that place blank. But I can subtract two hundred fifty-six once, so I write a 1 there, and there's 43 left. Now, I can subtract two sixteens, and there's 11 left. And 11 is B in hex."
0 |
4096 | 256 | 16 | 1 |
---|---|---|---|
1 | 2 | B |
Now, read the number off: 12B16 = 29910.
- Translate these decimal numerals to hexadecimal notation:
- 59
- 144
- 229
- 316
Notice that the algorithms for converting between binary and decimal are the same as the algorithms for converting between hexadecimal and decimal. These algorithms can be used to convert to and from any base.
- This algorithm runs into a problem after base 36. What's the problem and what's the solution?
- Convert 29910 to base 7.
In the future, consider moving 8.3.3 and 8.3.4 here as TIF and removing from 8.3. --MF, 12/1/17