I need to convert decimal to IEEE 32- floating point for a couple homework problems by hand. I was wondering if my answers were correct.
13.5 is 0 0011011 00000000 00000000 00000000
-65.125 is 1 1000001 00010000 00000000 00000000
I need to convert decimal to IEEE 32- floating point for a couple homework problems by hand. I was wondering if my answers were correct.
13.5 is 0 0011011 00000000 00000000 00000000
-65.125 is 1 1000001 00010000 00000000 00000000
Why don't you convert them "not by hand" and see if they are what you expect them to be?
Quzah.
Hope is the first step on the road to disappointment.
Decimal to Floating-Point Conversions
i used that tutorial.
The exponent is 8 bits, not 7 and you don't store the value of the integral part in the exponent. How do you expect to store the number 500?
Go back to study scientific notation a little more to refresh your memory of how that is represented. It's the same thing here except that this is base 2.
I'll use a different example, 11.25.
First write the number in binary:
11.25 is:
8 + 0 + 2 + 1 + 0 + 0.25 =
1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 + 0*2^-1 + 1*2^-2 =
1011.01
Now count how many times you have to move the decimal place to the left to move it to straight after the first digit:
101.101 = 1 time
10.1101 = 2 times
1.01101 = 3 times (so our exponent is 3)
What's left after the dot is the significand.
Now:
First bit = 0 because the number is positive.
We need to bias our exponent by 127 because that's the bias for a float. So our exponent becomes 127 + 3 = 130, and 130 in 8 binary bits is 10000010
Then comes our significand, which we pad with zeros to make it up to 23 bits:
01101000000000000000000
Then you put that together:
01000001 00110100 00000000 00000000
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"