whitey9999 said:
Since the SDD exam doesnt allow calculators do we actually have to do floating point to decimal conversions. If so can someone teach me an easier way than adding fractions with denominators up to like 2^23
Has anyone seen a Floating point in a past exam? either conversion to or from? (i havent looked yet)
Well, I have no idea about whether they are in past papers. Simply because I am too lazy to do SDD past papers.
However, I will try and remember/teach how to do this easily
Decimal to floating point
Ok, lets take the decimal 564.725
First, we work to the left of the decimal place;
564 = 512 + 32 + 16 + 4 = 1000110100
Now, for the right of the decimal place, my teacher taught me a little trick:
You keep doubling the decimal place and ignoring the first digit.
What you end up with is the binary representation for the part to the right of the decimal place.
...725
1.450
0.9
1.8
1.6
1.2
0.4
0.8
1.6
1.2
0.4
0.8
etc
As you can see it has started recurring.
So for the part after the decimal place we get:
.1011100110011001100110011 etc
Adding this with the part to the left of the decimal place we get:
1000110100.1011100110011001100110011
Now the sign bit is 0 as the number is positive.
Counting for exponent gives us 9
Now the exponent in binary = 9 + 127 (you add 127 to positive exponent) = 128 + 8 = 10001000
Now we have all we need, remember, you ignore the starting 1 in the mantissa:
0 (sign bit) 10001000 (exponent) 00011010010111001100110 (mantissa)
Total of 32 bits, 1 sign bit, 8 exponent, 23 mantissa.
And thats it, your done:
01000100000011010010111001100110
Hope that helps
Converting back can be a pain, simple, but a pain. Doubt you will be asked that in an exam, even more than I doubt you will be asked this =S
Just read your post, you asked for the other way, hmmm. Woops oh well, might help someone else. The only thing I can say is that after about 8 decimal places you have got a pretty good idea of what the decimal will be.
Floating point to decimal
0 10001000 00011010010111001100110
Using the answer from above:
Positive from sign bit (0)
10001000 = 128 + 8 = 127 + 9
Therefore exponent = 9
Applying this to our mantissa (don't forget to add the extra 1 to the front):
1000110100.10111001100110
Now: 1000110100 = 512 + 32 + 16 + 4 = 564
Now for after the decimal place:
= .5 + .125 + 0.0625 + 0.03125 + .... = 0.71875
Hmmm. This is going to get crap. I would honestly just stop there and say the answer is 564.72
Which is close enough..
If they did ask it in an exam, it wouldn't have anywhere near this many decimal places. They would probably try and use maybe a 2-3 byte floating point or something and an easy number like 564.25
Well that was a good and hopeless waste of time