Write a C (or Python or Java) program, call it binary Arithmetic with the following requirements:...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these algorithms questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Scott and Associates, Inc., is an accounting firm that has three new clients. Project leaders will be assigned to the three clients. Based on the different backgrounds and experiences of the leaders,...
-
When only a resistor is connected across the terminals of an ac generator (112 V) that has a fixed frequency, there is a current of 0.500 A in the resistor. When only an inductor is connected across...
-
A large iceberg in the shape of a cube has a mass density of \(917 \mathrm{~kg} / \mathrm{m}^{3}\) and floats upright in seawater that has a mass density of \(1024 \mathrm{~kg} / \mathrm{m}^{3}\)....
-
In Figure 8.4, are the contact force exerted by the table on the book and the gravitational force exerted by Earth on the book an interaction pair? Figure 8.4 (a) Book at rest on table (vector sum of...
-
Presented below are selected ledger accounts of Woods Corporation at December 31, 2012. Woods??s effective tax rate on all items is 34%. A physical inventory indicates that the ending inventory is...
-
9. An arrow 2.5 cm high is placed at a distance of 25 cm from a diverging mirror of focal length 20 cm., Find the nature, position and size of the image formed. 10. The image formed by a convex...
-
Del Conte Construction Company has experienced generally steady growth since its inception in 1976. Management is proud of its record of having maintained or increased its earnings per share in each...
-
A system using virtual memory with the paging technique has a page size of 1 KiB. The page table for a given process P contains the following six entries: [3, 4, *, 1, *, 8]. The machine has 4 GiB of...
-
A geometric Brownian motion with drift and volatility is defined by the equation ds = Sdt +oSdze Ito's lemma states that if G is a function of S and t, then G OG 10G + G (25s +. at zasz52dt +. The...
-
1) Small cylinder/cone objects are to be delivered to another location. These cubic objects will be placed inside a rectangular box for ease of management. Assumed the dimension of the cylinder is...
-
Liwei owns and operates fast food restaurant in Las Vegas, Nevada. Liwei traveled from Las Vegas to San Jose in early 2022 to discus acquiring a computer retail store. After a number of months of...
-
The Company has 4,500,000 common shares outstanding. Jerry Fry acquired 5% of these shares at a cost of $19 each. During the current year, the Company declares a 6% stock dividend which it designates...
-
SMC is a public school having five buses each plying in different directions for the transport of its school students. In view of a larger number of students availing of the bus service the buses...
-
Define the term Patent? What is the social and industrial significance of IPR in detail?
-
What can scientists learn by comparing the fossilized skeletons of extinct primates with the bones of modern species?
-
Carol Harris, Ph.D, CPA, is a single taxpayer and she lives at 674 Yankee Street, Durham, NC 27409. Her Social Security number is 793-52-4335. Carol is an Associate Professor of Accounting at a local...
-
Your supervisor has asked you to research the following situation concerning Owen and Lisa Cordoncillo. Owen and Lisa are brother and sister. In May 2012, Owen and Lisa exchange business pickup...
-
Yolanda is a cash basis taxpayer with the following transactions during the year: Cash received from sales of products........................................................................$65,000...
-
Variants and exception handlers are alternate flows for a use case. In which situations should one or the other be used?
-
Which elements an agile software team must consider to attribute effort to a product?
-
Why is the rounded Fibonacci series used to assign story points instead of the natural numbers?
Study smarter with the SolutionInn App