Page 251 - ARM 64 Bit Assembly Language
P. 251
240 Chapter 8
9 10 0
= 1024 + 240 + 2 + + +
16 256 4096
= 1266.6015625 10
8.1.2 Decimal to arbitrary base
When converting from base ten into another base, the integer and fractional parts are treated
separately. The base conversion for the integer part is performed in exactly the same was as
in Section 1.3.2, using repeated division by the base b. The fractional part is converted using
repeated multiplication. For example, to convert the decimal value 5.6875 10 to a binary repre-
sentation:
1. Convert the integer portion, 5 10 into its binary equivalent, 101 2 .
2. Multiply the decimal fraction by two. The integer part of the result is the first binary digit
to the right of the radix point.
Because x = 0.6875 × 2 = 1.375, the first binary digit to the right of the binimal point is
1. So far, we have 5.625 10 = 101.1 2 .
3. Multiply the fractional part of x by 2 once again.
Because x = 0.375 × 2 = 0.75, the second binary digit to the right of the binimal point is
0. So far, we have 5.625 10 = 101.10 2 .
4. Multiply the fractional part of x by 2 once again.
Because x = 0.75 × 2 = 1.50, the third binary digit to the right of the binimal point is 1.
So now we have 5.625 = 101.101.
5. Multiply the fractional part of x by 2 once again.
Because x = 0.5 × 2 = 1.00, the fourth binary digit to the right of the binimal point is 1.
So now we have 5.625 = 101.1011.
6. Since the fractional part of x is now zero, we know that all remaining digits will be zero.
The procedure for obtaining the fractional part can be accomplished easily using a table, as
shown below:
Operation Result
Integer Fraction
.6875 × 2 = 1.375 1 .375
.375 × 2 = 0.75 0 .75
.75 × 2 = 1.5 1 .5
.5 × 2 = 1.0 1 .0
Putting it all together, 5.6875 10 = 101.1011 2 . After converting a fraction from base 10 into
another base, the result should be verified by converting back into base 10. The results from