Question: Write a method that parses a binary number as a string into a decimal integer. The function header is as follows: int parseBinary(String binaryString) Assume

Write a method that parses a binary number as a string into a decimal integer. The function header is as follows: int parseBinary(String binaryString) Assume that we do not support parsing of negative binary numbers.

* Make parseBinary() method throw an IllegalArgumentException in cases

- when the string that is being parsed is not a binary number (contains characters other that 0 or1).

- when the string is too long and the resulting number is too large to be stored as an integer

*Test your method in main(). Use try/catch block to test the exception-throwing part of the code. Do not use user input hard-code all of your test cases instead.

Example, binary string 10001 is 17: 1*24+ 0*23+1*22+0*21+1*20 = 16+1 = 17 parseBinary(10001) returns 17.

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 Databases Questions!