Question: Hi! I have a question for programming with c. I tried to implement it but my solution does not work. How would the code look

Hi!

I have a question for programming with c. I tried to implement it but my solution does not work. How would the code look like to answer the question below:

Create a program that outputs the IEEE 754 double-precision binary representation for a passed floating-point number. The floating point number is passed as a command line parameter, where a valid floating point number has the following parts: (1) optional plus or minus sign (2) a non-empty sequence of decimal digits which optionally contains a decimal point (3) optionally an e or E with an optional plus or minus sign and a non-empty sequence of decimal digits.

The user passes a floating point number as command line parameter. (1) If no parameter is passed, the program prints the text "usage: ./s09e02 " on the standard error output stderr and terminates with the return value EXIT_FAILURE. (2) If an error occurs when converting the string into a double precision floating point number or if the whole parameter cannot be transformed into a number, the error message "ERROR: is not a valid double! Extracted double component: Remaining: " is output on the standard error output stderr and the program terminates with the return value EXIT_FAILURE. The placeholder is replaced by the command line parameter, is replaced as a decimal number with six decimal places by the part of the command line parameter which could be successfully transformed into a floating point number, and is replaced by the remaining part which could no longer be transformed into a floating point number.

The text "Number: Binary representation: " is printed on the standard output, where the placeholder is replaced by the floating point number as decimal number in exponential representation with six decimal places, which was passed as command line parameter.

The sign (sign), exponent (exponent) and mantissa (mantissa) components of the floating point number are calculated and output in the format " " with three spaces before sign and one space each before exponent and mantissa on the standard output.

The text "sign exponent mantissa " is printed on the standard output.

The program is terminated with EXIT_SUCCESS.

Tip:

You can use a union consisting of a double and a uint64_t component to get the bit representation of a double precision floating point number.

The strtod function can be helpful in converting the passed parameter.

Keep exactly to the format of the examples and do not output any additional text!

I can send you my code if you want to so that you can look for the mistake there.

Thank you!

Best regards,

Fiona

The output should look like this:

./s09e02 4.1 Number: 4.100000e+00 Binary representation: 0 10000000001 0000011001100110011001100110011001100110011001100110 sign exponent mantissa

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!