Binary Calculator Programmed in C. NOT C++. ONLY C PLEASE. You will have to create a calculator that is able to read in

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Binary Calculator Programmed in C. NOT C++. ONLY C PLEASE. You will have to create a calculator that is able to read in

Post by answerhappygod »

Binary Calculator Programmed in C. NOT C++. ONLY C PLEASE.
You will have to create a calculator that is able to read in anequation from a file. The input will be a long series of binarydigits [0, 1] where different sequences of numbers representspecific operations. There are 4 specific input sequences thatwiill designate what the following binary sequence represents:Delimiter, Number, Symbol, Not a Number (NaN). Based on thesesequences, any binary sequence can be broken down into an equation.Your goal is to be able to solve the equation and print the result.The exact parameters and definitions of each of the input sequencesis further detailed below. Each input sequence is 4 digitslong.
0001 Delimiter: This input sequence denotes the end of thecurrent equation and the start of a new equation. Upon receivingthis input, the program should print the result of the previousequation. An equation will always end with a delimiter.
0010 Number: This input sequence denotes that the followingsequence is a number, x. This input sequence will be followed by a4 digit binary number. This number will signify the amount ofbinary digits that the number x is comprised of.
0100 Symbol: This input sequence denotes that the followingsequence is a mathematical symbol. This input sequence will befollowed by a 2 digit binary number. There are three mathematicalsymbols corresponding to the 2 bit pattern. ”00” is addition (+),”01” is subtraction (-), ”10” is multiplication (*). The 2 bitpattern will never be ”11”.
1
• 1000 Not a number (NaN): This input sequence denotes that thefollowing number is invalid. If this sequence is found the currentequation should be considered invalid. The program should print”NaN” and the program should continue at the start of the nextequation or terminate if no other equations exist.
The following rules will also be in effect for thisassignment:
All inputs, computations, and results will all be positivenumbers
Order of operations should be ignored. Namely, all equationsshould be resolved left to right.
Any computation that results in a number that exceeds themaximum value that can stored in an integer will nullify theequation and cause the equation to result in ”NaN”.
Input format: This program takes one sequence from the commandline. The sequence will be a binary sequence. The sequence shouldthen be read using the previous rules in order to determine theunderlying equation(s).
Output format: Your program should output the result of each ofthe equations in base 10. Each equation will result in some output.The output will be either a numeric solution to the equation or thevalue ”NaN”. The solution to each equation should be printed on adifferent line.
Example Execution:
Some sample runs and results are:
To break down each of the examples:test 1: 0010 0001 1 0100 00 0010 0010 11 0001
can be interpreted as: [Number, 1 digit long, 1, Symbol,addition, Number, 2 digits long, 3, Delimiter] or
1+3
test 2: 0010 0011 111 0001 0010 0010 10 0100 01 0010 0001 10001
can be interpreted as: [Number, 3 digits long, 7, Delimiter,Number, 2 digits long, 2, Symbol, subtraction, Number, 1 digitlong, 1, Delimiter] or
7 2-1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply