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
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; } ///
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
string convertToHex(float num) { unsigned int* ptr = reinterpret_cast 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 HERE ARE THE RESULTS AND CLEARLY THE HEX AND MANTISSA SHOULD BE THOSE VALUES
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
