Книга: Introduction to Microprocessors and Microcontrollers

Hexadecimal, or ‘hex’ to its friends

Hexadecimal, or ‘hex’ to its friends

Counting from 0 to 15 will mean 16 different digits and so has a base of 16. What the digits look like really doesn’t matter. Nevertheless, we may as well make it as simple as possible.

The first 10 are easy, we can just use 0123456789 as in denary. For the last six we have decided to use the first six letters of the alphabet: ABCDEF or abcdef.

The hex system starts as:

Hex Denary
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A 10
B 11
C 12
D 13
E 14
F 15

When we run out of digits, we just put a 1 in the second column and reset the first column to zero just as we always do.

So the count will continue:

10 16
11 17
12 18
13 19
14 20
15 21
16 22
17 23
18 24
19 25
1A 26
1B 27
1C 28
1D 29
1E 30
1F 31
20 32

… and so on.

It takes a moment or two to get used to the idea of having numbers that include letters but it soon passes. We must be careful to include the base whenever necessary to avoid confusion. The base is usually written as H, though h or 16 would still be acceptable.

‘One eight’ in hex is equal to twenty-four in denary. Notice how I avoided quoting the hex number as eighteen. Eighteen is a denary number and does not exist in hex. If you read it in this manner it reinforces the fact that it is not a denary value. Here are the main options in order of popularity:

16H = 2410

16H = 2410

16h = 2410

16h = 2410

1616 = 2410

The advantages of hex

1 It is very compact. Using a base of 16 means that the number of digits used to represent a given number is usually fewer than in binary or denary.

2 It is easy to convert between hex and binary and fairly easy to go between hex and denary. Remember that the microprocessor only works in binary, all the conversions between hex and binary are carried out in other circuits (Figure 3.1).


Figure 3.1 Hex is a good compromise

Оглавление книги


Генерация: 0.033. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз