Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include #include #include using namespace std; void collect(double& x); double collect2(); void sign_collector(double x, char& s); void isolate(double, int&, double&); void

#include  #include  #include  #include  #include  #include  #include  using namespace std; void collect(double& x); double collect2(); void sign_collector(double x, char& s); void isolate(double, int&, double&); void display(char sign, int intpart, double decpart, string integerbinary, string decimalbinary, int shifts, string shiftbinary); void inttobin(int intpart, string& binarystring, int); void decimaltobinary(double decpart, string& decimalbinary); void exponentval(string binarydata, int exponent, int& shifts); string convertToIEEE(float num); string convertToHex(float num); void showMantissa(float num); int main() { // declarations/ initialization double number = 0.0; char sign; int intpart = 0; double decpart = 0.0; string integerbinary = ""; string decimalbinary = ""; string shiftbinary = ""; int bits = 8; string binarydata = ""; int exponent = 0; int shifts = 0; //0. menu to choose from // 1. ask the user to enter the value to convert to IEEE collect(number); /umber = collect2(); // 2. find the sign b sign_collector(number, sign); //3. function to isolate integer part from the decimal // 10.25 - integerpart=10, decimalpart= 0.25 isolate(number, intpart, decpart); //4. convert intpart to binary inttobin(intpart, integerbinary, bits); //inttobin(intpart, binarystring, 8); // 5.function to convert the decimal part to binary decimaltobinary(decpart, decimalbinary); //6. calculating exponent binarydata = integerbinary + "." + decimalbinary; exponentval(binarydata, exponent, shifts); //7. converting exponent to binary inttobin(shifts, shiftbinary, bits); // 8. after normlization (mantissa) (shifting the dec point) // 9. concatenate(sign, exponent, mantissa) //10. conversion to hex // display display(sign, intpart, decpart, integerbinary, decimalbinary, shifts, shiftbinary); return 0; } ////////////////////////////////////////////////////////////////////////// // // communicating via pass by reference void collect(double& x) { // 1. ask the user to enter the value to convert to IEEE cout > x; } ///  /// ////////////////////////////////////////////////////////////////////// /// communicate via function type /// double collect2() { double x; // 1. ask the user to enter the value to convert to IEEE cout > x; return x; } //////////////////////////////////////////////////////////////////// // a function to extract a number sign void sign_collector(double x, char& s) { if (x >= 0) s = '0'; // 0 for positive else s = '1'; // 1 for negative } ///////////////////////////////////////////////////////////////////// // a function that takes a double value and returns an integer and a void isolate(double number, int& intpart, double& decpart) { number = abs(number); intpart = abs((int)number); // type cast decpart = abs(number - intpart); } void inttobin(int intpart, string& binarystring, int bits) { for (int i = 0; i  // once found collect address and leave int len = binarydata.length(); int onelocation = 0; int declocation = 0; for (int i = 0; i  bits(reinterpret_cast(&num)); for (int i = 31; i >= 0; i--) { result += bits[i] ? '1' : '0'; if (i == 31 || i == 23) { result += ' '; } } return result; } string convertToHex(float num) { stringstream stream; stream (&num); string result(stream.str()); if (result.length() (mantissa)  

MY CODE ABOVE IS SUPPOSED TO TAKE A NUMBER THE USER ENTERS AND SHOW THE IEEE CONVERSION OF THAT NUMBER BUT I NEED HELP FIXING THE MANTISSA AND HEXADECIMAL PARTS BECAUSE THEY ARE GIVING ME INCORRECT VALUES

FOR EXAMPLE THE MANTISSA ONLY SHOWS A BUNCH OF 0's AND THE HEXADECIMAL WHEN I TYPE IN 10.25 AS THE NUMBER SHOWS 001df2ecWHEN THE RIGHT ANSWER SHOULD BE A4

THANK YOU AND PLEASE SEND THE CORRECTED CODE THAT DISPLAYS THE RIGHT MANTISSA AND HEXADECIMAL CONVERSIONS

image text in transcribed

here are the results and the last 2 parts are clearly wrong so i need help fixing it so please send the entire corrected code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

More Books

Students also viewed these Databases questions

Question

U11 Informing Industry: Publicizing Contract Actions 317

Answered: 1 week ago