Reference no: EM132210224
Write a program in JAVA to read in a 32-bit pattern and translate to a IEEE-754 floating point number. Do not use library routines.
Be sure to look for infinity, -infinity, zero and NaN patterns. ?( This is what I NEED, My SPECIFIED NEED is please use the import: import javax.swing.JOptionPane; for the input and output, a string to turn the int to binary,then a loop to check and see if there are any special patterns, example: NaN, -infinity, infinity, ect... If not check it with something like this ..............
sign=(inputString.CharAt(0)=='0'?1:-1);
?String expString=inputString,substring(1,8);
?String mainString=inputSting.substring(9)
?Code below am having issues with!! AH please help thank you
import javax.swing.JOptionPane;
public class IEEE_754_2 {
public static void main(String[] args) {
String inputString,ieee_754;
inputString = JOptionPane.showInputDialog("Enter the 32bit number");
int sign=(inputString.charAt(0)=='0'?1:-1);
String expString=inputString.substring(1,9);
String mainString=inputString.substring(9);
int intExp = Integer.parseInt(expString, 2);
intExp = intExp -127;
int decimal_part=0;
double fraction =0.0;
for(int index=0; index <mainString.length();index++){
fraction = fraction + Integer.parseInt(""+mainString.charAt(index))*Math.pow(2,-1*(index+1));
}
ieee_754=""+(fraction+1)*sign*Math.pow(2,intExp);
JOptionPane.showMessageDialog(null,ieee_754);
}
}