// Prog: dec2float.cpp // compute the float representation of a number in the open interval (0,2) #include #include // PRE: 0 < x < 2 // POST: The binary representation of x was written to std::cout void representation(const float x) { assert(0 < x && x < 2); // x = w * 2^e float w = x; int e = 0; // Extract exponent from x // (as long as w < 1, decrement e and double w) ... // Now we have 1 <= w < 2, apply rule from lecture std::cout << "Significand: "; for (...) { ... std::cout << bi; // bi is the ith bit } std::cout << "\nExponent: " << e << "\n"; } int main () { // input std::cout << "Decimal number x (0 < x < 2) =? "; float x; std::cin >> x; // Computation and output representation(x); return 0; }