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: 2246750 • 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.

I need to use JOption panes for input and output and this code below should be used :

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;

    }

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 );
}
}

OUTPUT

Binary equivalent of 19.5:
1000001100111000000000000000000
Decimal equivalent of 1000001100111000000000000000000:
19.5

// The parseInt() function parses a string argument and returns an integer of the specified radix(base).

//The java.lang.Float.intBitsToFloat() method returns the float value corresponding to a given bit representation.

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