Cryptography Reference
In-Depth Information
WRITING A NUMBER IN HEX
For hex numbers, we use the base number 16 instead of 10 in decimal (and 2 in
binary). Thus:
1. The digits of a hex number can, in theory, take any of the values between 0
and 15.
2. Every digit in a hex number will bemultiplied by some power of 16. The powers
of 16 start with 0 (the furthest digit to the right) and then increase from right
to left.
The first requirement causes a slight problem, since it will be hard to determine
whether 12 means the digit 1 followed by the digit 2, or whether we mean the hex
'digit' 12. Thus we replace the hex digits 10, 11, 12, 13, 14 and 15 by A , B , C , D ,
E and F , respectively. So, in practice, the digits of a hex number take any of the
values between 0 and 9, and between A and F .
CONVERTING HEX TO DECIMAL
Converting from hex to decimal follows the same principles as binary to decimal,
except that nowwe are usingmultiples and powers of 16. Consider the hex number
B 5 F 16 . It follows that:
16 2 )
16 1 )
16 0 )
B 5 F 16 =
( B
×
+
(5
×
+
( F
×
(11 × 16 2 ) + (5 × 16 1 ) + (15 × 16 0 )
=
=
(11
×
256)
+
(5
×
16)
+
(15
×
1)
=
2816
+
80
+
15
=
2911 10 .
Thus B 5 F in hex is 2911 in decimal.
CONVERTING BETWEEN BINARY AND HEX
A useful feature of hex is that there is a very simple way of converting between
binary and hex (which does not work for converting either of them to, or from,
decimal). This uses Table A.1, which displays the binary equivalents of the 16 hex
digits.
Converting from hex to binary simply involves replacing each hex digit with
its binary equivalent from Table A.1. For example, to convert B 5 F 16 into binary
we first make the substitutions:
B 16 =
1011 2 ,
5 16 =
0101 2 ,
F 16 =
1111 2
from Table A.1 to get:
B 5 F 16 = 101101011111 2 .
 
Search WWH ::




Custom Search