ALU { public String integerMultiplication (String operand1, String operand2, int length) { String formattedOperand1 = complementLength(operand1, length); String formattedOperand2 = complementLength(operand2, length); String minusOperand1 = negation(formattedOperand1); String thatTwoRegisters = repeatedString("0", length)+formattedOperand2+"0"; for(int i=0;i<length;i++){ switch(thatTwoRegisters.substring(thatTwoRegisters.length()-2, thatTwoRegisters.length())){ case "10":{ String intermediateResult = adder(minusOperand1, thatTwoRegisters.substring(0, length), '1', length).substring(1); thatTwoRegisters = intermediateResult + thatTwoRegisters.substring(length); break; } case "01":{ String intermediateResult = adder(formattedOperand1, thatTwoRegisters.substring(0, length), '0', length).substring(1); thatTwoRegisters = intermediateResult + thatTwoRegisters.substring(length); break; } case "00": case "11": break; } thatTwoRegisters = ariRightShift(thatTwoRegisters, 1); } boolean notOverflow = thatTwoRegisters.substring(0,length+1).indexOf("1")==-1 || thatTwoRegisters.substring(0,length+1).indexOf("0")==-1; return (notOverflow ?"0" : "1")+ thatTwoRegisters.substring(length,2*length); }  static void main(String[] args); static final boolean floatIsInfinity(String input, int eLength, int sLength); static final String complementLength(String binary, int length); static final String repeatedString(String str, int times); static final String bitOp(String oneBitOperand1, String oneBitOperand2, BinaryOperator<Boolean> op); static final boolean isSignTheSame(String binary1, String binary2); static String movePoint(String operand, int offset); static final char charOp(BinaryOperator<Boolean> op, Character... bits); static final String stringOp(String operand1, String operand2, BinaryOperator<Boolean> op); static final boolean xor(boolean operand1, boolean operand2); static int minBinaryLong(int number); static String integerBinRepresentationInMinLength(String decimalNumber); static String get2sComplement(String binaryNumber, boolean isNegative); String integerRepresentation(String number, int length); String floatRepresentation(String number, int eLength, int sLength); String ieee754(String number, int length); String integerTrueValue(String operand); String floatTrueValue(String operand, int eLength, int sLength); String negation(String operand); String leftShift(String operand, int n); String logRightShift(String operand, int n); String ariRightShift(String operand, int n); String fullAdder(char x, char y, char c); String claAdder(String operand1, String operand2, char c); String oneAdder(String operand); String adder(String operand1, String operand2, char c, int length); String integerAddition(String operand1, String operand2, int length); String integerSubtraction(String operand1, String operand2, int length); String integerMultiplication(String operand1, String operand2, int length); String integerDivision(String operand1, String operand2, int length); String signedAddition(String operand1, String operand2, int length); String floatAddition(String operand1, String operand2, int eLength, int sLength, int gLength); String floatSubtraction(String operand1, String operand2, int eLength, int sLength, int gLength); String floatMultiplication(String operand1, String operand2, int eLength, int sLength); String floatDivision(String operand1, String operand2, int eLength, int sLength); String trueFormDivision(String operand1, String operand2, int length); static final BinaryOperator<Boolean> booleanAnd; static final BinaryOperator<Boolean> booleanOr; static final BinaryOperator<Boolean> booleanXOR; }
@Test public void testIntegerMultiplication() { ALU alu = new ALU(); assertEquals("000001100", alu.integerMultiplication("0100", "0011", 8)); }
@Test public void testIntegerMultiplication1(){ assertEquals("10000",ALU.integerMultiplication("1000", "0010", 4)); }
@Test public void testIntegerMultiplication2(){ assertEquals("11110",ALU.integerMultiplication("1101", "0110", 4)); }