ALU { public String adder (String operand1, String operand2, char c, int length) { String normalizedOperand1 = complementLength(operand1, length); String normalizedOperand2 = complementLength(operand2, length); char carry = c; StringBuilder finalResult = new StringBuilder(); int partsLeft = length/4; int highestBits = length%4; while(partsLeft>0){ String claResult = claAdder(normalizedOperand1.substring(highestBits + 4*partsLeft-4, highestBits + 4*partsLeft), normalizedOperand2.substring(highestBits+ 4*partsLeft-4, highestBits+4*partsLeft), carry); finalResult.insert(0, claResult.substring(1)); carry = claResult.charAt(0); partsLeft--; } for(int i=highestBits-1;i>=0;i--){ String bitResult = fullAdder(normalizedOperand1.charAt(i), normalizedOperand2.charAt(i), carry); carry = bitResult.charAt(0); finalResult.insert(0, bitResult.charAt(1)); } if (normalizedOperand1.charAt(0)==normalizedOperand2.charAt(0) && normalizedOperand1.charAt(0) != finalResult.charAt(0)){ finalResult.insert(0, "1"); }else{ finalResult.insert(0, "0"); } return finalResult.toString(); }  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 testAdder() { ALU alu = new ALU(); assertEquals("000000111", alu.adder("0100", "0011", '0', 8)); }
@Test public void testAdder1(){ assertEquals("000001000",ALU.adder("0100", "0011", '1', 8)); }
@Test public void testAdder2(){ assertEquals("000000000000000000000000001000111",ALU.adder("01100100", "11100011", '0', 32)); }
@Test public void testAdder3(){ assertEquals("11110",ALU.adder("0110", "0111", '1', 4)); }
@Test public void testAdder4(){ assertEquals("10001",ALU.adder("1000", "1000", '1', 4)); }