Question: I need help creating a binary class for a bigger project I am working on. I was given an outline but need instruction on how

I need help creating a binary class for a bigger project I am working on. I was given an outline but need instruction on how to complete it in the way instructed. The outline is as follows and this is written in Java. Any help would be helpful. I outlined the methods according to how they are suppose to function.

public class Binary { /** Constant defines the maximum length of binary numbers. */ private static final int MAX_LENGTH = 32; /** * Converts a two's complement binary nubmer to signed decimal * * @param b The two's complement binary number * @return The equivalent decimal value * @exception IllegalArgumentException Parameter array length is longer than MAX_LENGTH. */ public static long binToSDec(boolean[] b) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return

// Example of throwing an IllegalArgumentException // Student must write code for the required exceptions in other methods. // If the exception condition is true, throw the exception if(b.length > MAX_LENGTH) { // If the condition is true, the exception will be thrown // and the method execution will stop. throw new IllegalArgumentException("parameter array is longer than " + MAX_LENGTH + " bits."); } // If the method execution reaches this point, the exception was // not thrown. // Write the rest of the method here.

return 0; } /** * Converts an unsigned binary nubmer to unsigned decimal * * @param b The unsigned binary number * @return The equivalent decimal value * @exception IllegalArgumentException Parameter array length is longer than MAX_LENGTH. */ public static long binToUDec(boolean[] b) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return return 0; }

/** * Converts a signed decimal nubmer to two's complement binary * * @param d The decimal value * @param bits The number of bits to use for the binary number. * @return The equivalent two's complement binary representation. * @exception IllegalArgumentException Parameter is outside valid range that can be represented with the given number of bits. */ public static boolean[] sDecToBin(long d, int bits) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return return new boolean[MAX_LENGTH]; }

/** * Converts an unsigned decimal nubmer to binary * * @param d The decimal value * @param bits The number of bits to use for the binary number. * @return The equivalent binary representation. * @exception IllegalArgumentException Parameter is outside valid range that can be represented with the given number of bits. */ public static boolean[] uDecToBin(long d, int bits) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return return new boolean[MAX_LENGTH]; }

/** * Returns a string representation of the binary number. Uses an underscore * to separate each group of 4 bits. * * @param b The binary number * @return The string representation of the binary number. */ public static String toString(boolean[] b) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return return "not completed"; }

/** * Returns a hexadecimal representation of the unsigned binary number. Uses * an underscore to separate each group of 4 characters. * * @param b The binary number * @return The hexadecimal representation of the binary number. */ public static String toHexString(boolean[] b) { // PROGRAM 1: Student must complete this method // return value is a placeholder, student should replace with correct return return "not completed"; }

}

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!