4. Convert from decimal to single precision machine representation.
Steps:
(a) Identify the sign (length 1):
• 0 for +
• 1 for -
(b) Identify the mantissa (length 23):
• First, convert the decimal number (without the sign) to binary. It is recommended
to convert from base 10 to 8 to 2.
• Second, move the decimal forwards or backwards so that it is written in the the
form a.b
1
b
2
b
3
· · · × 2
n
where n is the number of spaces you moved the decimal (can
be positive or negative depending on the direction the decimal was moved).
• The mantissa is the number b
1
b
2
b
3
· · ·
• Add enough zeros to the mantissa so that it is 23 digits long.
(c) Identify the exponent (length 8):
• Solve c − 127 = n for c. You know n from calculation of the mantissa.
• Note that c is in base 10. Convert it to binary. Again it is recommended to convert
from base 10 to 8 to 2.
• If there is a leading 0, eliminate is so you have a number of 8 digits in length.
(d) Put it all together:
• Put the value for the sign in the first slot.
• Next write down the 8 digits of the number for the exponent step.
• Lastly write down the mantissa with the extra zeros so the number has a total of
32 digits.
(e) Convert to hexidecimal:
• Divide the 32 digit number into 8 numbers each of length 4.
• Convert each 4 digit number from binary to hexidecimal. This is your final answer.
Example: Convert -52.234375 to single precision machine representation.
(a) Identify the sign: The number is negative, which implies 1.
(b) Identify the mantissa:
• We will convert 52.234375 to binary:
First convert the integer part:
52 ÷ 8 = 6 R4
6 ÷ 8 = 0 R6
So (52)
10
= (64)
8
= (110 100)
2
Second convert the fraction part:
0.234375 ∗ 8 = 1.875000
0.875 ∗ 8 = 7.000
So (0.234375)
10
= (0.17)
8
= (0.001 111)
2
.
3
相关文档
评论