Книга: Advanced PIC Microcontroller Projects in C
1.22.2 Converting a Decimal Number into Floating Point
Разделы на этой странице:
1.22.2 Converting a Decimal Number into Floating Point
To convert a given decimal number into floating point, carry out the following steps:
• Write the number in binary.
• Normalize the number.
• Find the mantissa and the exponent.
• Write the number as a floating point number.
Some examples follow:
Example 1.34
Convert decimal number 2.2510 into floating point.
Solution 1.34
Write the number in binary:
2.2510 = 10.012
Normalize the number:
10.012 = 1.0012 ? 21
Here, s = 0, e – 127 = 1 or e = 128, and f = 00100000000000000000000.
(Remember that a number 1 is assumed on the left side, even though it is not shown in the calculation). The required floating point number can be written as:
s e f
0 10000000 (1)001 0000 0000 0000 0000 0000
or, the required 32-bit floating point number is:
01000000000100000000000000000000
Example 1.35
Convert the decimal number 134.062510 into floating point.
Solution 1.35
Write the number in binary:
134.062510 = 10000110.0001
Normalize the number:
10000110.0001 = 1.00001100001 ? 27
Here, s = 0, e – 127 = 7 or e = 134, and f = 00001100001000000000000.
The required floating point number can be written as:
s e f
0 10000110 (1)00001100001000000000000
or, the required 32-bit floating point number is:
01000011000001100001000000000000
- Numbers
- 1.6 Converting Binary Numbers into Decimal
- 1.7 Converting Decimal Numbers into Binary
- 1.8 Converting Binary Numbers into Hexadecimal
- 1.9 Converting Hexadecimal Numbers into Binary
- 1.10 Converting Hexadecimal Numbers into Decimal
- 1.11 Converting Decimal Numbers into Hexadecimal
- 1.12 Converting Octal Numbers into Decimal
- 1.13 Converting Decimal Numbers into Octal
- 1.14 Converting Octal Numbers into Binary
- 1.15 Converting Binary Numbers into Octal
- 1.16 Negative Numbers