Question: ( Java Programming ) Write two Java methods: one to convert a 2 s complement binary number to decimal and another to do the reverse.

(Java Programming) Write two Java methods: one to convert a 2s complement binary number to decimal and another to do the reverse. Your code must implement the steps of one of the algorithms presented in class. DO NOT use any java methods which do decimal-to-binary or binary-to-decimal conversion for you. You should not use any data structures and should not use a String (or StringBuilder) to perform an unnecessary intermediate conversion between the int and char[]. If your code uses predefined methods to do the conversion such that you fail to demonstrate a step-by-step understanding of the algorithms presented in class, then you will lose at least half of the points for the programming portion of this assignment. The method declarations are provided below. You may create private helper methods to remove any redundancy, if you wish, but the public method signatures below must not be changed. /*** Accepts an array of characters representing the bits in a two's complement number * and returns the decimal equivalent. ** precondition: * This method requires that the maximum length of the parameter array is 16.** postcondition: * The value returned is the decimal equivalent of the two's complement parameter. * The parameter array is unchanged. ** @param theBits an array representing the bits in a two's complement number * @throws IllegalArgumentException if the length of the parameter array >16.* @return the decimal equivalent of the two's complement parameter */public static int convert2sCompToDecimal(final char[] theBits){/*** Accepts a decimal parameter and returns an array of characters * representing the bits in the 16 bit two's complement equivalent. ** precondition: * This method requires that the two's complement equivalent * won't require more than 16 bits ** postcondition: * The returned array represents the 16 bit two's complement equivalent * of the decimal parameter. ** @param theDecimal the decimal number to convert to two's complement * @throws IllegalArgumentException if the parameter cannot be represented in 16 bits. * @return a 16 bit two's complement equivalent of the decimal parameter */public static char[] convertDecimalTo2sComp(final int theDecimal){You must complete the methods in the provided Convert.java class. Unit tests are provided in the ConvertTest.java class. All provided unit test should pass on your methods. Do NOT make any changes to the provided unit tests.Add comments to your code, as needed, to explain your logic.

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!