Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objective: To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and vice versa. Inputs: Number in Decimal format

Objective: To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and vice versa.

Inputs: • Number in Decimal format (including special case of 0) • Number in IEEE-754 format (including special cases)

Output: • Equivalent number in IEEE-754 format • Equivalent number in Decimal

Specification:

The program converts a number based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Quit program

Special Cases The program must also check for these special IEEE cases: • + 0 • -0 • + infinity • - Infinity • NaN

What to do:

• Make sure your code compiles with zyBooks’ zyLabs compiler--if it does not compile with zyBooks’ compiler it will be graded as not compiling, even if it compiles on your compiler on your desktop/laptop at home. Only 4 submissions will be permitted! • Include all prompts and other messages as shown in the sample run that follows. • Case and whitespaces will be ignored • To mask a number to extract a field, use “variable” & “constant” • To print a number in hexadecimal format, use “%x” • To use the math library, use “include ” for functions like “pow(x,y)” to raise “x” to the “y” power • Feel free to use the template “skeleton” code provided on Canvas for the assignment

What NOT to do (any violation will result in an automatic score of 0 on the assignment):

• Do NOT modify the choice values (1, 2, 3) or input characters and then try to convert them to integers--the test script used for grading your assignment will not work correctly. • Do NOT turn in an outdated version of the assignment downloaded from the Internet (coursehero, github, etc.) or a version that was coded by someone else (former student, tutor, etc.) • Do NOT use any self-created or external libraries that cannot be located/utilized by zylabs • Do NOT turn in your assignment coded in another programming language (C++, C#, Java, Python, Perl, etc.)—it will NOT compile under zyLabs C compiler.

What to submit to ZYLAB (Section 22.16):

The source code as a single C file uploaded to zyLab by the deadline of 11:59pm PST (-20% per consecutive day for late submissions, up to the 4th day—note 1 minute late counts as a day late, 1 day and 1 minute late counts as 2 days late, etc.).

Sample test run

This sample run contains all possible cases that will be tested, either individually, in their own Test Bench, or combined in a single Test Bench.

Note: • Inputs in the test run will not show up on the output display. They are included here for clarity. • Output result titles are preceded by two asterisks. • Whitespaces and case will be ignored by auto-grading, but all messages must be identical to those shown below in both wording and spelling. This includes any hyphens, asterisks and right-parentheses. • I suggest you use zyLab’s workbench in Develop Mode to pre-test your submissions. That is, make up your own input data and see if you get the correct results.

Test Inputs These are the input test values. They do not appear on the output of the run.

1 2.5 2 40200000 1 0 2 -126 2 FFFFFFFF 3

Test Output

Floating-point conversion:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

Enter the decimal representation:

*** Sign: 0 *** Biased exponent: 10000000 *** Mantissa: 01000000000000000000000 *** IEEE HEX: 40200000

Floating-point conversion:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

Enter the IEEE-754 representation:

*** Sign: + *** Unbiased exponent: 1 *** Normalized decimal: 1.250000 *** Decimal: 2.500000

Floating-point conversion: -
1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

Enter the decimal representation:

*** Sign: 0 *** Biased exponent: 00000000 *** Mantissa: 00000000000000000000000

***The IEEE-754 representation is: 0.000000

Floating-point conversion:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

Enter the IEEE-754 representation:

*** Sign: - *** Special case: NaN

Floating-point conversion:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

Enter the IEEE-754 representation:

*** Sign: - *** Special case: NaN

Floating-point conversion:

1) Decimal to IEEE-754 conversion 2) IEEE-754 to Decimal conversion 3) Exit

Enter selection:

*** Program Terminated Normally

#include
#include

/*************************/
void "OPTION #1"()
{
   /* declare local variables */

   /* prompt for floating point decimal number */

   /* Check for 0--if so, print result */

   /* Print sign: if number>0, sign is 0, else 1 */
   /* take absolute value of number before generating significand */

   /* Normalize number:
   while number >2, divide by 2, increment exponent
   while number <1, multiply by 2, decrement exponent
   */

/* Bias exponent by 127 and print each bit in binary with 8-iteration for-loop*/

/* Hide 1 and print significand in binary with 23-iteration for-loop*/
 
   /* Print IEEE-754 representation */
return;
}

/***********************************************************************/
void "OPTION #2"()
{
/* declare local variables */
 
/* prompt for IEEE-754 representation */
 
   /* check for special cases: 0, -0, +infinity, -infinity, NaN,
       if so, print and return */

   /* Mask sign from number: if sign=0, print "+", else print "-" */
 
   /* Mask biased exponent and significand from number */
   /* If biased exponent=0, number is denormalized with unbiased exponent of -126,
       print denormalized number as fraction * 2^(-126), return */

   /* Unbias exponent by subtracting 127 and print */
   /* Add hidden 1 and print normalized decimal number */
 
   /* Print decimal number */
   return;
 
}

int main()
{
/* declare local variables */
/* until user chooses to quit, prompt for choice and select appropriate function */
 
return 0;
}


Step by Step Solution

There are 3 Steps involved in it

Step: 1

C code include include void decimaltoIEEE754 declare local variables float decimalnumber int exponent 0 int bit32 for int i 0 i 32 i biti 0 prompt for ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Algorithms questions

Question

What is the difference between the body and the mind?

Answered: 1 week ago