The base 16 or hexadecimal system is a natural way to rep-resent the binary data stored in a computer. It is more com-pact than binary because four binary digits can be replaced by a single “hex” digit.
The following table gives the corresponding decimal, binary, and hex values from 0 to 15:
Decimal Binary Hex
0 0 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Note that decimal and hex digits are the same from 0 to 9, but hex uses the letters A–F to represent the digits cor-responding to decimal 10–15. The system extends to higher numbers using increasing powers of 16, just as decimal uses powers of 10: For example, hex FF represents binary 11111111 or decimal 255. Many of the apparently arbitrary numbers encountered in programming can be better under-stood if one realizes that they correspond to convenient groupings of bits: FF is eight bits, sufficient to hold a single character (see characters and strings). In low-level pro-gramming memory addresses are also usually given in hex (see assembler).
No comments:
Post a Comment