Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java ) program, call it binaryArithmetic with the following requirements: the programs take 3 space - separated string arguments, i . e .

Write a Java) program, call it binaryArithmetic with the following requirements:
the programs take 3 space-separated string arguments, i.e., a binary number, 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 corresponding 2's complement. This operation should be done in a separate function, called void get2Complement(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:
$ binaryArithmetic // call without arguments
$ Usage: binaryArithmetic Binary 1>+ Binary 2>
$ binaryArithmetic 01000010+00000011
$01000010+00000011=01000101
$ binaryArithmetic 01009010+00000011
$ Illegal character in binary string.
Please do in java only .
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions