What is
hexadecimal?
Hexadecimal is a number system just
like the decimal number system except that it uses 16 digits instead of 10
digits to represent its numbers.
The decimal number: Sixty-three
thousand, three hundred and eight can be written as 63,308. The number can be
broken down into its different parts: 6 of 10000, 3 of 1000, 3 of 100, 0 of 10
and 8 of 1. And can be reconstructed again by adding those numbers together:
(6*10000)+(3*1000)+(3*100)+(0*10)+(8*1) = 63,308.
Similarly the hexadecimal number
(this looks and sound pretty weird): F-seven-four-C can be written as $F74C.
Hexadecimal numbers are not usually pronounced as numbers but are usually
pronounced using their individual digits.
Note the dollar sign at the front
indicates that this is a hexadecimal number. (Otherwise how would we know that
1234 and FACE are actually hexadecimal numbers and not the decimal number
1,234 and the word face?).
$F74C can also be broken down into
its different parts: 15 of 4096, 7 of 256, 4 of 16 and 12 of 1. And can be
reconstructed again by adding those numbers together:
(15*4,096)+(7*256)+(4*16)+(12*1) = 63,308 = $F74C.
Where did all those numbers (15,
4096, 256, 16 and 12) come from?
In order to construct numbers using
16 digits, 6 more digits had to be found because there are only 10 digits in our
decimal number system. The 6 extra digits are defined to be A, B, C, D, E and F
and they represent the values 10, 11, 12, 13, 14 and 15 respectively.
So hopefully the reason that 15 was
used in place of F and that 12 was used in place of C is clear.
What is not so clear is why does
each hex digit get multiplied by factors of 16? Well in the case of the decimal
(or base 10) number system each digit position is 10 times more than the
position to its right. In the case of the hexadecimal (or base 16) number system
each digit position is 16 times more than the position to its right.
Why would anyone use the
hexadecimal system?
The hexadecimal system is a very
convenient way to write binary values. Each hexadecimal digit represents exactly
4 bits (a nybble). So two and only two hexadecimal digits are required to
represent 8 bits (a byte). And 4 and only 4 hexadecimal digits are required to
represent 16 bits (a word).
The range 0..255 can be written in
hexadecimal as $00..$FF, while the range 0..65,535 can be written in hexadecimal
as $0000..$FFFF. The hexadecimal number system is a neater and more intuitive
way to write and convert binary numbers into something that can be understood
more easily.
Converting from hexadecimal to
binary and from binary to hexadecimal is a snap and can easily be done without a
calculator.
For example: to convert the 16 bit
binary number: 11110111 01001100 into a hexadecimal number simply split the
binary number into nybbles (4 bit sections) and convert each nybble to its
single hex digit:
1111 = 8+4+2+1 = 15 = $F
0111 = 0+4+2+1 = 07 = $7
0100 = 0+4+0+0 = 04 = $4
1100 = 8+4+0+0 = 12 = $C
= $F74C
But to convert the same 16 bit
binary number: 1111011101001100 into decimal would require the following
calculations:
Starting at the right hand end of
the binary number...
(0*1)+(0*2)+(1*4)+(1*8)+(0*16)+(0*32)+(1*64)+(0*128)+
(1*256)+(1*512)+(1*1,024)+(0*2,048)+(1*4,096)+(1*8,192)+(1*16,384)+(1*32,768)
Which evaluates to...
4+8+64+256+512+1,024+4,096+8,192+16,384+32,768
=63,308
Decimal to Hexadecimal conversion
chart
0 $00
|
16 $10
|
32 $20
|
48 $30
|
64 $40
|
80 $50
|
96 $60
|
112 $70
|
1 $01
|
17 $11
|
33 $21
|
49 $31
|
65 $41
|
81 $51
|
97 $61
|
113 $71
|
2 $02
|
18 $12
|
34 $22
|
50 $32
|
66 $42
|
82 $52
|
98 $62
|
114 $72
|
3 $03
|
19 $13
|
35 $23
|
51 $33
|
67 $43
|
83 $53
|
99 $63
|
115 $73
|
4 $04
|
20 $14
|
36 $24
|
52 $34
|
68 $44
|
84 $54
|
100 $64
|
116 $74
|
5 $05
|
21 $15
|
37 $25
|
53 $35
|
69 $45
|
85 $55
|
101 $65
|
117 $75
|
6 $06
|
22 $16
|
38 $26
|
54 $36
|
70 $46
|
86 $56
|
102 $66
|
118 $76
|
7 $07
|
23 $17
|
39 $27
|
55 $37
|
71 $47
|
87 $57
|
103 $67
|
119 $77
|
8 $08
|
24 $18
|
40 $28
|
56 $38
|
72 $48
|
88 $58
|
104 $68
|
120 $78
|
9 $09
|
25 $19
|
41 $29
|
57 $39
|
73 $49
|
89 $59
|
105 $69
|
121 $79
|
10 $0A
|
26 $1A
|
42 $2A
|
58 $3A
|
74 $4A
|
90 $5A
|
106 $6A
|
122 $7A
|
11 $0B
|
27 $1B
|
43 $2B
|
59 $3B
|
75 $4B
|
91 $5B
|
107 $6B
|
123 $7B
|
12 $0C
|
28 $1C
|
44 $2C
|
60 $3C
|
76 $4C
|
92 $5C
|
108 $6C
|
124 $7C
|
13 $0D
|
29 $1D
|
45 $2D
|
61 $3D
|
77 $4D
|
93 $5D
|
109 $6D
|
125 $7D
|
14 $0E
|
30 $1E
|
46 $2E
|
62 $3E
|
78 $4E
|
94 $5E
|
110 $6E
|
126 $7E
|
15 $0F
|
31 $1F
|
47 $2F
|
63 $3F
|
79 $4F
|
95 $5F
|
111 $6F
|
127 $7F
|
128 $80
|
144 $90
|
160 $A0
|
176 $B0
|
192 $C0
|
208 $D0
|
224 $E0
|
240 $F0
|
129 $81
|
145 $91
|
161 $A1
|
177 $B1
|
193 $C1
|
209 $D1
|
225 $E1
|
241 $F1
|
130 $82
|
146 $92
|
162 $A2
|
178 $B2
|
194 $C2
|
210 $D2
|
226 $E2
|
242 $F2
|
131 $83
|
146 $93
|
163 $A3
|
179 $B3
|
195 $C3
|
211 $D3
|
227 $E3
|
243 $F3
|
132 $84
|
148 $94
|
164 $A4
|
180 $B4
|
196 $C4
|
212 $D4
|
228 $E4
|
244 $F4
|
133 $85
|
149 $95
|
165 $A5
|
181 $B5
|
197 $C5
|
213 $D5
|
229 $E5
|
245 $F5
|
134 $86
|
150 $96
|
166 $A6
|
182 $B6
|
198 $C6
|
214 $D6
|
230 $E6
|
246 $F6
|
135 $87
|
151 $97
|
167 $A7
|
183 $B7
|
199 $C7
|
215 $D7
|
231 $E7
|
247 $F7
|
136 $88
|
152 $98
|
168 $A8
|
184 $B8
|
200 $C8
|
216 $D8
|
232 $E8
|
248 $F8
|
137 $89
|
153 $99
|
169 $A9
|
185 $B9
|
201 $C9
|
217 $D9
|
233 $E9
|
249 $F9
|
138 $8A
|
154 $9A
|
170 $AA
|
186 $BA
|
202 $CA
|
218 $DA
|
234 $EA
|
250 $FA
|
139 $8B
|
155 $9B
|
171 $AB
|
187 $BB
|
203 $CB
|
219 $DB
|
235 $EB
|
251 $FB
|
140 $8C
|
156 $9C
|
172 $AC
|
188 $BC
|
204 $CC
|
220 $DC
|
236 $EC
|
252 $FC
|
141 $8D
|
157 $9D
|
173 $AD
|
189 $BD
|
205 $CD
|
221 $DD
|
237 $ED
|
253 $FD
|
142 $8E
|
158 $9E
|
174 $AE
|
190 $BE
|
206 $CE
|
222 $DE
|
238 $EE
|
254 $FE
|
143 $8F
|
159 $9F
|
175 $AF
|
191 $BF
|
207 $CF
|
223 $DF
|
239 $EF
|
255 $FF
|
|