V22.0101 ..... Homework 8 ..... Fall 2006
Floating Point Numbers
Assigned: Wed Nov 22
Due: Tue Dec 5
Write a simple GUI program that asks the user to enter a float
value as a string and extracts the sign, exponent and significand
and displays them nicely in a graphics window.
Use Float.parseFloat to convert the user-input string to its float
representation, and then OurFloat.getIEEEBits.java in
OurFloatDemo.java
to convert the float value to a binary string showing the internal bit
representation. Then you can use String.subString to extract the
sign bit (the first bit in the string), the exponent bits (the next 8)
and the significand (the last 23 bits). Display the sign as a "+"
or "-". Display the exponent as a decimal integer; this means you have
to first convert the bitstring to an int (you can use the overloaded
Integer.parseInt that allows you to specify that the radix (base) of
the string is 2), and then subtract the shift (127) (see Table 1 of
Notes on floating point).
Display the significand as a binary string, including the binary
point and the hidden bit in front of it (normally 1, but 0 in the
case of the number zero or subnormals; see the first line of Table 1).
Take special action the case of infinities and NaNs (see last line of
Table 1).
When you have this working, do a similar thing for double using another window with longer fields, referring to Table 2 of the same notes.