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.
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