Exercise 1

Instructions

Implement each of the functions below in a file Exercise1.java in package aup.cs.
Make sure to debug all functions!
Once you finish all parts, upload them before the deadline to Blackboard.

Part 1

/**
 * Print 1 character to System.out
 * For example printCharInt('*') prints 42
 * @param c the character to print
 */ 
static void printCharInt(char c)

/**
 * Print the base 2 of an integer
 * For example printIntBase2(42) should print 101010
 * @param n the number to print
 */ 
static void printIntBase2(int n)

/**
 * Print the given bit array to System.out
 * It should print 1 for each true value and 0 for a false one
 * @param arr the boolean array to print
 */ 
static void printBitArray(boolean[] arr)

Part 2

/**
 * Convert a char into a 16 bits array
 * @param c the char to print
 * @return a boolean array of length 16 representing the bit presentation of the character
 */ 
static boolean[] char2bitArray(char c)

/**
 * Convert a 16 bits array into a char
 * @param arr a boolean array of length 16 representing a bit array 
 * @return the character denoted by the bit array
 */ 
static char bitArray2char(boolean[] arr)

/**
 * Test the previous two coding functions by converting the text into an array of characters. 
 * Then for each character, it converts it into a bit array and then converts the bit array back into a character.
 * Finally, the program constructs a new String given an array of all the generated characters.
 * Print the text before and after the transformations.
 * @param text an input string to test
 */ 
static void testCoding(String text)

Part 3

/**
 * Computes the next bit of LFSR
 * @param arr the bit array (initially the seed)
 * @param coefs the binary coefficients
 * @return a boolean which is the combination of adding (modulo 2) the multiplication of each current bit with a coefficient
 */ 
static boolean FeedbackLFSR(boolean[] arr, boolean[] coefs)

/**
 * Computes the next state of the bit array
 * @param arr the bit array (initially the seed)
 * @param coefs the binary coefficients
 * @return the next bit to use for encoding.
 */ 
static boolean feedbackUpdateLFSR(boolean[] arr, boolean[] coefs)

/**
 * Encode the char by XORing each bit with the returned one from feedbackUpdateLFSR 
 * @param c the char to encode
 * @param arr the bit array (initially the seed)
 * @param coefs the binary coefficients
 * @return the encoded char
 */ 
static char encodeCharLFSR(char c, boolean[] arr, boolean[] coefs)

/**
 * Encode the char array by encoding each char in it
 * @param chars the char array to encode
 * @param arr the bit array (initially the seed)
 * @param coefs the binary coefficients
 * @return the encoded char
 */ 
static char[] encodeCharArrayLFSR(char[] chars, boolean[] arr, boolean[] coefs)

/**
 * Test the LFSR encoding and decoding
 * 1. copy the bit array (the seed) and out aside
 * 2. Transform the text into a char array
 * 3. Encode using encodeCharArrayLFSR and print
 * 4. Decode the encoded message using the copied seed and encodeCharArrayLFSR and print
 * @param text the text to test
 * @param arr the bit array (initially the seed)
 * @param coefs the binary coefficients
 */ 
static void testLFSR(String text, boolean[] arr, boolean[] coefs)