knapsack.java
/** helper method that takes a boolean array and turns in into an
	*   integer.  This is used by the decrypt method to turn binary
	*   representations of messages into integers that can be written
	*   into a file.
	*   @param array the array to convert into an integer
	*   @return the integer represented by the array
	*   @throws IllegalArgumentException if the length of the boolean array
	*   is not 8.
	*/
helper method that takes a boolean array and turns in into an
integer.  This is used by the decrypt method to turn binary
representations of messages into integers that can be written
into a file.
@param array the array to convert into an integer
@return the integer represented by the array
@throws IllegalArgumentException if the length of the boolean array
is not 8.
helper method that takes a boolean array and turns in into an integer . This is used by the decrypt method to turn binary representations of messages into integers that can be written into a file . @param array the array to convert into an integer @return the integer represented by the array @throws IllegalArgumentException if the length of the boolean array is not 8 .
public static int toByte(boolean[] array) throws IllegalArgumentException {
		if (array.length==8) {
			int[] bits = new int[8];
			bits[0] = 0b00000001;
			bits[1] = 0b00000010;
			bits[2] = 0b00000100;
			bits[3] = 0b00001000;
			bits[4] = 0b00010000;
			bits[5] = 0b00100000;
			bits[6] = 0b01000000;
			bits[7] = 0b10000000;
			int newByte = 0x00;
			byte test = 0b00000000;
			for(int i = 0; i< 8; i++) {
				if(array[i]) {
					newByte = newByte | bits[i];
				}
			}
			return newByte;
		}
		else {
			throw new IllegalArgumentException("To create a new byte, an array length\nof 8 is required.");
		}
	}
public static int toByte ( boolean [ ] array ) throws IllegalArgumentException { if ( array . length == 8 ) { int [ ] bits = new int [ 8 ] ; bits [ 0 ] = 0b00000001 ; bits [ 1 ] = 0b00000010 ; bits [ 2 ] = 0b00000100 ; bits [ 3 ] = 0b00001000 ; bits [ 4 ] = 0b00010000 ; bits [ 5 ] = 0b00100000 ; bits [ 6 ] = 0b01000000 ; bits [ 7 ] = 0b10000000 ; int newByte = 0x00 ; byte test = 0b00000000 ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( array [ i ] ) { newByte = newByte | bits [ i ] ; } } return newByte ; } else { throw new IllegalArgumentException ( "To create a new byte, an array length\nof 8 is required." ) ; } }
helper method that takes a boolean array and turns in into an
   integer.
helper method that takes a boolean array and turns in into an integer .