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 s 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 decimaltobinary or binarytodecimal 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 stepbystep 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 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 @return the decimal equivalent of the two's complement parameter public static int convertsCompToDecimalfinal char theBits Accepts a decimal parameter and returns an array of characters representing the bits in the bit two's complement equivalent. precondition: This method requires that the two's complement equivalent won't require more than bits postcondition: The returned array represents the 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 bits. @return a bit two's complement equivalent of the decimal parameter public static char convertDecimalTosCompfinal int theDecimalYou 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
