Question: #include #include #include using namespace std; //Function Prototypes void signbit(double number, string &x); // checks sign of number; positive (0) or negative (1) void zoro(double
#include#include #include using namespace std; //Function Prototypes void signbit(double number, string &x); // checks sign of number; positive (0) or negative (1) void zoro(double number, int &whole, double & fraction); // separates the integer value from the decimal value (ex. -10.25) string wholeconverter(int whole); // converts the integer value to binary (ex. 10 = 1010) string fractionconverter(double number); // converts the decimal value to binary (ex. 0.25 = 0100 0000 0000 0000 0000 0000) string numberconverter(string wholebinary, string fracbin); // converts number entered into binary (ex. 10.25 = 00001010.0100000000000....) string mantissaconverter(string wholebinary, string fracbin); //displays mantissa of converted number (ex. 01001000 00000000 .....) string exponentconverter(string fullbinary); //converts integer of entered number into binary (ex. 130 = 10000010) void fullconverter(string fracbin); //displays entered number in IEEE 754 single precision binary (ex. -10.25 = 01000001 00100100 00000000 00000000) void hexconverter(double number); //displays entered number into IEEE 754 single precision HEX (ex. -10.25 = C1240000) //C++ entry point int main() { //Declaration string x; // Sign string wholebinary, fracbin, fullbinary, mantissa; int whole, exponent; double number, fraction, binary; char choice, hex; //Initialization fraction = 0.00; number = 0.00; exponent = 0; whole = 0; binary = 0.00; hex = 0; choice = 0; x = ""; fracbin = ""; wholebinary = ""; fullbinary = ""; mantissa = ""; signbit(number, x); zoro(number, whole, fraction); wholebinary = wholeconverter(whole); fracbin = fractionconverter(fraction); fullbinary = numberconverter(wholebinary, fracbin); mantissa = mantissaconverter(wholebinary, fracbin); // Menu Display cout << "PLEASE ENTER A NUMBER TO DISPLAY THE IEEE 754 FLOATING POINT OPTIONS." << endl; cin >> number; cout << " " << endl; cout << "PLEASE CHOOSE ONE OF THE FOLLOWING OPERATIONS: " << endl; cout << "1. DISPLAY THE SIGN BIT VALUE" << endl; cout << "2. DISPLAY THE INTEGER PART IN BOTH BASE-10 AND BINARY FORMATS" << endl; cout << "3. DISPLAY THE DECIMAL PART IN BOTH BASE-10 AND BINARY FORMATS" << endl; cout << "4. DISPLAY THE NUMBER ENTERED IN BOTH BASE-10 AND BINARY FORMATS" << endl; cout << "5. DISPLAY THE MANTISSA IN BINARY FORMAT" << endl; cout << "6. DISPLAY THE EXPONENT IN BOTH BASE-10 AND BINARY FORMAT" << endl; cout << "7. DISPLAY THE IEEE 754 SINGLE PRECISION BINARY FORMAT" << endl; cout << "8. DISPLAY THE IEEE 754 SINGLE PRECISION HEX FORMAT" << endl; cout << " " << endl; //Operation Selection cin >> choice; switch (choice) { case '1': signbit(number, x); // Function Call if (number >= 0) { cout << "SIGN BIT IS (" << x << ") SINCE THE NUMBER ENTERED IS POSITIVE." << endl; } else { cout << "SIGN BIT IS (" << x << ") SINCE THE NUMBER ENTERED IS NEGATIVE." << endl; } break; case '2': zoro(number, whole, fraction); // Function Call wholebinary = wholeconverter(whole); // Function Call cout << "NUMBER (" << abs(whole) << ") IN BASE-10 IS EQUAL TO ("<< wholebinary << ") IN BINARY" << endl; break; case '3': zoro(number, whole, fraction); // Function Call wholebinary = wholeconverter(whole); // fracbin = fractionconverter(fraction); // Function Call cout << "NUMBER (" << abs(fraction) << ") IN BASE-10 IS EQUAL TO (" << fracbin << ") IN BINARY" << endl; break; case '4': zoro(number, whole, fraction); //Function Call wholebinary = wholeconverter(whole); // fracbin = fractionconverter(fraction); // Function Call fullbinary = numberconverter(wholebinary, fracbin); cout << "NUMBER(" << abs(number) << ") IN BASE-10 IS EQUAL TO (" << fullbinary << ") IN BINARY" << endl; break; case '5': zoro(number, whole, fraction); //Function Call wholebinary = wholeconverter(whole); // fracbin = fractionconverter(fraction); // Function Call fullbinary = numberconverter(wholebinary, fracbin); mantissa = mantissaconverter(wholebinary, fracbin); // Function Call cout << "MANTISSA IS (" << mantissa << ") IN BINARY." << endl; break; case '6': exponentconverter(fullbinary); // Function Call cout << "NUMBER (exponent ex.) IN BASE-10 IS EQUAL TO (exponenttobinary(exponent,binary) ex.) IN BINARY." << endl; break; case '7': fullconverter(fracbin); // Function Call break; case '8': hexconverter(number); // Function Call break; default: cout << "INVALID INPUT" << endl; break; } return 0; } ///////////////////////////////////////////////// // signbit function // checks the sign of the number, positive or negative // void type // 2 parameters; one pass by value (number) and one pass by reference (&x) // number, &x void signbit(double number, string &x) { if (number >= 0.00) { x = '0'; } else { x = '1'; } } //////////////////////////////////////////////////// // zoro function // void function // seperates the integer value from the decimal value // 3 parameters; one pass by value and two pass by reference // number, whole, fraction void zoro(double number, int &whole, double &fraction) { // declartion //int whole; //double fraction; // initialization fraction = 0.0; whole = 0; whole = (int)number; fraction = number - whole; // no return statment //return a, b, c, d; only the one before the ; will be reported back } /////////////////////////////////////////////////// // wholeconverter function // string function // Converts the integer value to binary // 1 parameter; pass by value // whole string wholeconverter(int whole) { //declaration string wholeb; //initialization wholeb = ""; if (whole < 0) whole = whole * -1; whole = abs(whole); while (whole > 0) { if (whole % 2 == 0) { wholeb = "0" + wholeb; } else { wholeb = "1" + wholeb; } whole = whole / 2; } return wholeb; } //////////////////////////////////////// // fractionconverter function // string function // converts the decimal value to binary // 1 parameter, pass by value // fraction string fractionconverter(double num) { // result string result = ""; int flag = 0; //if (num <0) num = num * -1; //big O num = num; while (flag <= 30) // number of position mantissa precision { flag++; // increment for precision num = num * 2; if (num >= 1) { result = result + '1'; num = num - 1; // num = num - (int)num; } else result = result + '0'; } return result; } //////////////////////////////////////// // numberconverter function // string type // displays the number entered into binary format // 2 parameters, both pass by value // number, fracbin string numberconverter(string wholebinary, string fracbin) { string result = ""; result = wholebinary + "." + fracbin; return result; } //////////////////////////////////////// // mantissaconverter function // string type // displays the mantissa of the converted number in binary format // 1 parameter, pass by value // mantissa string mantissaconverter(string wholebinary, string fracbin) { string result = ""; result = wholebinary + fracbin; string mantissa(result, 1, 24); if (mantissa.substr(1, 23) == "1") { mantissa = mantissa.substr(0, 22) + "1"; } return mantissa; } //////////////////////////////////////// // exponentconverter function // string type // converts the exponent of the entered number into binary format // 1 parameter, pass by value // exponent string exponentconverter(string fullbinary) { string exponent = ""; exponent = fullbinary.length() - 1; }
Need help finishing this code to show full IEEE single precision conversion
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
