Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in JAVA to read in a 32-bit pattern and translate to a IEEE-754

ID: 2247579 • Letter: W

Question

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)


Relatively new to coding, so the simpler the better. That way I understand what I am doing , thanks

Explanation / Answer

public class main {

         

    // Convert the 32-bit binary into the decimal

    private static float GetFloat32( String Binary )

    {

        int intBits = Integer.parseInt(Binary, 2);

        float myFloat = Float.intBitsToFloat(intBits);

        return myFloat;

    }

     

    // Get 32-bit IEEE 754 format of the decimal value

    private static String GetBinary32( float value )

    {

        int intBits = Float.floatToIntBits(value);

        String binary = Integer.toBinaryString(intBits);

        return binary;

    }  

    /**

     * @param args

     */

    public static void main(String[] args)

    {

        // Convert 19.5 into IEEE 754 binary format..

        String str = GetBinary32( (float) 19.5 );

        System.out.println( "Binary equivalent of 19.5:" );

        System.out.println( str );

       

        // .. and back again

        float f = GetFloat32( str );

        System.out.println( "Decimal equivalent of " + str + ":");

        System.out.println( f );       

    }

}

//this is the basic code, you can do the UI work as u wish.
// for special patterns, from your description it sounds like you know how things work. I think you can do it easily

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote