Question: Write a C (or Python or Java) program, call it binary Arithmetic with the following requirements: the programs take 3 space-separated string arguments, i.e.,


Write a C (or Python or Java) program, call it binary Arithmetic 

Write a C (or Python or Java) program, call it binary Arithmetic with the following requirements: the programs take 3 space-separated string arguments, i.e., a binary num- ber, an operator (+ or -) and a binary number. the program parse each of the three argument and, in case any of them is not valid, prints an error message and exits. This parsing of binary numbers should be done in a separate function, called int parse(char If the operator is -, the second binary number is transformed into its cor- responding 2's complement. This operation should be done in a separate function, called void get 2Complement (char *). The addition of the two binary strings is performed in another function called void Add(char *num1, char *num2, char *result) . Finally, your program should print the result in the following format: num1 op num2 = result, e.g., 01000001 + 00000011 = 01000100 For simplicity, assume you are dealing with 8-bit signed numbers in the range of -128 +127. Test runs: $ binary Arithmetic // call without arguments $ Usage: binary Arithmetic $ binary Arithmetic 01000010+ 00000011 $ 01000010+ 00000011 = 01000101 $ binary Arithmetic 01009010 + 00000011 $ Illegal character in binary string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!