Please use matlab to solve this problem and read the questio

Please use matlab to solve this problem and read the question carefully.

Write a function file that will convert from IEEE-754 floating-point representation to decimal.

I asked this question before. But it provided me with the wrong answer. The code that was provided converts decimal to IEEE754. While I asked from the conversion from IEEE754 to decimal. The code that was provided before does the exact opposite and it doesnt really help me. Please provide me with a code that accept an IEE754 number as an input and gives out an output of decimal number. Thank you very much

Solution

function file that convert IEEE-754 floating-point representation to decimal: #include #include #if UINT_MAX >= 0xFFFFFFFF typedef unsigned uint32; #else typedef unsigned long uint32; #endif #define C_ASSERT(expr) extern char CAssertExtern[(expr)?1:-1] C_ASSERT(sizeof(uint32) * CHAR_BIT == 32); C_ASSERT(sizeof(uint32) == sizeof(float)); double Ieee754SingleDigits2DoubleCheat(const char s[32]) { uint32 v; float f; unsigned i; char *p1 = (char*)&v, *p2 = (char*)&f; v = 0; for (i = 0; i < 32; i++) v = (v << 1) + (s[i] - \'0\'); for (i = 0; i < sizeof(f); i++) *p2++ = *p1++; return f; } double Ieee754SingleDigits2DoubleNoCheat(const char s[32]) { double f; int sign, exp; uint32 mant; int i; sign = s[0] - \'0\'; exp = 0; for (i = 1; i <= 8; i++) exp = exp * 2 + (s[i] - \'0\'); exp -= 127; if (exp > -127) { mant = 1; // The implicit \"1.\" exp -= 23; } else { mant = 0; // No implicit \"1.\" exp = -126; // See your IEEE-54 formulas exp -= 23; } for (i = 9; i <= 31; i++) mant = mant * 2 + (s[i] - \'0\'); f = mant; while (exp > 0) f *= 2, exp--; while (exp < 0) f /= 2, exp++; if (sign) f = -f; return f; } int main(void) { printf(\"%+g\ \",IEEE754SingleDigits2DoubleNoCheat(\"110000101100010010000000000000000\")); printf(\"%+g\ \",IEEE754SingleDigits2DoubleNoCheat(\"010000101100010010000000000000000\")); printf(\"%+g\ \",IEEE754SingleDigits2DoubleCheat(\"000000000100000000000000000000000\")); printf(\"%+g\ \",IEEE754SingleDigits2DoubleNoCheat(\"100000000100000000000000000000000\")); printf(\"%+g\ \",IEEE754SingleDigits2DoubleCheat(\"000000000000000000000000000000000\")); printf(\"%+g\ \",IEEE754SingleDigits2DoubleNoCheat(\"000000000000000000000000000000000\")); return 0; }
Please use matlab to solve this problem and read the question carefully. Write a function file that will convert from IEEE-754 floating-point representation to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site