This project is just the original, unabridged version of Project 4, except that the final implementations of multiplication and division must be done without conversion to floating point, as described below. (You may, however, use conversion to floating-point in your prototype solution (Project 5) without penalty.)
The minimum requirements of the prototype solution (Project 5) are the following.
Overflow occurs when the absolute value of the number is too large for the number of integer bits available to represent its integer part. Underflow occurs when the number is too close to zero for the number of fraction bits available to represent its fractional part. Both overflow and underflow are possible for both positive and negative numbers.
Implement a program to simulate a binary, fixed-point calculator of user-specified precision, up to a maximum of 64 binary digits each for the integer and fractional number fields. Support simple addition, subtraction, multiplication, and division of both nonnegative and negative numbers.
00011.01000 ( 3.250 dec ) + 01010.01100 ( 10.375 dec ) = 01101.10100 ( 13.625 dec )Conversion from binary (or hex.) to decimal can always be done exactly.
a * b = (a_p 2^p + a_{p-1} 2^{p-1} + ... + a_{1-p} 2^{1-p} + a_{-p} 2^{-p} ) * (b_p 2^p + b_{p-1} 2^{p-1} + ... + b_{1-p} 2^{1-p} + b_{-p} 2^{-p} ) = c_{2p}2^{2p} + c_{2p-1}2^{2p-1} + ... + c_{-2p}2^{-2p} ,where the coefficients ai, bj, and ck are all just bits (0 or 1).
c_i = sum_j a_{i-j} b_j,where the sum is over j = -p, -p+1, ..., p-1, p, and we let a_k = b_k = 0 when k is not between -p and p.
Print a short menu explaining how to operate the program. Request and read in the user's requested number of digits (precision) for each number's integer and fraction fields. Request and read in a numerical value, x, as a binary fixed-point number. REPEAT Prompt for and read in an operator (q,m,c,p,h,b,d,+,-,*, or /). The prompt may be simply a list of possible inputs: qmcphbd+-*/>. If the operator is a 'q' or 'Q', terminate execution (quit). Else If the operator is an 'm', redisplay the short menu explaining how to operate the program. Else If the operator is a 'c', (re)set x to zero. Else If the operator is a 'p', read in a new precision and reset all current data values to the new precision. Else If the operator is an 'h', switch to hexadecimal I/O format. Else If the operator is an 'b', switch (back) to binary I/O format. Else If the operator is a 'd', print decimal approximations alongside all binary values until 'd' is reentered ('d' is a toggle). Else display an appropriate error message and continue. Request and read in a second numerical value, y, as a binary fixed-point number. Perform the indicated binary operation and overwrite x by its value, displaying the result to the screen as a complete calculation:<x-value> <operator> <y-value> = <new-x-value>UNTIL DONE