Page 253 - ARM 64 Bit Assembly Language
P. 253
242 Chapter 8
Therefore, 15 11 = 23.243 6 . To check the result, we can convert it back into base ten as fol-
24 10
lows:
1
0
1 × 6 + 3 × 16 + 2 × 6 −1 + 4 × 6 −2 + 3 × 6 −2
2 4 3
= 15 + + +
6 36 216
72 24 3
= 15 + + +
216 216 216
99
= 15 +
216
11
= 15
24
8.1.2.1 Bases that are powers-of-two
Converting fractional values between binary, hexadecimal, and octal can be accomplished in
the same manner as with integer values. However, care must be taken to align the radix point
properly. As with integers, converting from hexadecimal or octal to binary is accomplished
by replacing each hex or octal digit with the corresponding binary digits from the appropriate
table shown in Fig. 1.3.
For example, to convert 5AC.43B 16 to binary, we just replace “5” with “0101,” replace “A”
with “1010,” replace “C” with “1100,” replace “4” with “0100,” replace “3” with “0011,”
replace “B” with “1011,” So, using the table, we can immediately see that 5AC.43B 16 =
010110101100.010000111011 2 . This method works exactly the same for converting from
octal to binary, except that it uses the table on the right side of Fig. 1.3.
Converting fractional numbers from binary to hexadecimal or octal is also very easy using
the tables. The procedure is to split the binary string into groups of bits, working outwards
from the radix point, then replace each group with its hexadecimal or octal equivalent. For ex-
ample, to convert 01110010.1010111 2 to hexadecimal, just divide the number into groups of
four bits, starting at the radix point and working outwards in both directions. It may be neces-
sary to pad with zeroes to make a complete group on the left or right, or both. Our example
is grouped as follows: |0111|0010.1010|1110| 2 . Now each group of four bits is converted
to hexadecimal by looking up the corresponding hex digit in the table on the left side of
Fig. 1.3. This yields 72.AE 16 . For octal, the binary number would be grouped as follows:
|001|110|010.101|011|100| 2 . Now each group of three bits is converted to octal by looking
up the corresponding digit in the table on the right side of Fig. 1.3. This yields 162.534 8 .Note
that the conversion to octal required the addition of leading and trailing zeroes.