For example given the following input denoting an unsigned


Write a code in the file Convert.java. Your code should go into a method with the following signature. May write the own main method to test the code. The graders will ignore your main method:

public static int convert (String binaryString, boolean signBit){}

In the beginning of the class you were taught an algorithm for converting binary strings to their decimal integer equivelant.

The sign bit is as follows: true for signed integer, false for unsigned integer. For a signed integer, the most significant bit is the leftmost bit, with 0 for positive and 1 for negative.

For example, given the following input denoting an unsigned integer:

10, false

After applying the algorithm, this string is converted into:

2

And given the following input denoting a signed integer:

01, true

After applying the algorithm, this string is converted into:

1

Write the method called convert that takes a string and a boolean as inputs, converts it to its decimal integer equivalent, and returns the resulting integer.

Solution Preview :

Prepared by a verified Expert
Business Management: For example given the following input denoting an unsigned
Reference No:- TGS02518908

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)