Question: #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

void decimaltobinary(double decpart, string& decimalbinary) { 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

string convertToIEEE(float num) { string result; bitset 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) { unsigned int* ptr = reinterpret_cast(&num); unsigned int bits = *ptr; stringstream stream; stream

void showMantissa(float num) { union { float f; unsigned int u; } x = { num }; unsigned int mantissa = x.u & ((1 >= (23 - 10); // 10 is the number of mantissa bits in single-precision float cout (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

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

#include #include #include #include #include #include #include using namespace std; void collect(double&

HERE ARE THE RESULTS AND CLEARLY THE HEX AND MANTISSA SHOULD BE THOSE VALUES

10.25 1 st one location is 4 15 t dec location is 8 exponent is 1026 The sign of the number is Positive The integer part is : 10 The decimal part is :0.25 The binary value of 10 is (00001010) The binary value of 0.25 is (0100000000000000000000000000000000000000000000000000) The whole number 10.25 converted to binary 00001010.0100000000000000000000000000000000000000000000000000 The exponent is 3 converted to binary 00000011 IEEE 754 binary representation: 00000000010100000101010110011000 IEEE 754 hexadecimal representation: 00000000 Mantissa in binary form: 0000000000

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!