Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

#include  #include  #include  using namespace std; // global var. // prototypes 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); 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); //number = 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 << "Please enter a value to convert to IEEE :" << endl; cin >> x; } ///  /// ////////////////////////////////////////////////////////////////////// /// communicate via function type /// double collect2() { double x; // 1. ask the user to enter the value to convert to IEEE cout << "Please enter a value to convert to IEEE :" << endl; cin >> 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 < bits; i++) { if (intpart % 2 == 0) binarystring = "0" + binarystring; else binarystring = "1" + binarystring; intpart = int(intpart / 2); } } void decimaltobinary(double decpart, string& decimalbinary) { for (int i = 0; i < 52; i++) { decpart *= 2; if (decpart < 1) { decimalbinary = decimalbinary + "0"; } else { decimalbinary = decimalbinary + "1"; decpart -= 1; } } } void exponentval(string binarydata, int exponent, int &shifts) { //1. find the location of the first 1 occurance // 0101010101.01010110101010110101010 //-----> // once found collect address and leave int len = binarydata.length(); int onelocation = 0; int declocation = 0; for (int i = 0; i < len; i++) { // find the first "1" position if (binarydata.at(i) == '1') { onelocation = i; break; } } for (int i = 0; i < len; i++) { // find the first "1" position if (binarydata.at(i) == '.') { declocation = i; break; } } cout << "1st one location is " << onelocation << endl; cout << "1st dec location is " << declocation << endl; shifts = abs(onelocation - declocation)-1; exponent = 1023 + shifts; cout << "exponent is " << exponent << endl; } ////////////////////////////////////////////////////////////////////////// // a function for verification void display(char sign, int intpart, double decpart, string integerbinary, string decimalbinary, int shifts, string shiftbinary) { string st = ""; if (sign == '0') st = "Positive"; else st = "Negative"; cout << "The sign of the number is " << st << endl; cout << "The integer part is :" << intpart << endl; cout << "The decimal part is :" << decpart << endl; cout << "The binary value of " << intpart << " is (" < 

ABOVE IS MY CODE TO TURN A NUMBER THE USER ENTERS INTO IEEE FORMAT, I NEED YOU TO ADD A FUNCTION THAT ALSO TURNS THEIR NUMBER INTO IEEE HEXDECIMAL LAYOUT AND ANOTHER FUNCTION THAT SHOWS THE MANTISSA USING C++

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_2

Step: 3

blur-text-image_3

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

7. Explain why retirees may be valuable as part-time employees.

Answered: 1 week ago

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago