ALU { public String claAdder (String operand1, String operand2, char c) { StringBuilder result = new StringBuilder(); BiFunction<Character, Character, Integer> pi = (x,y)->charOp(booleanOr, x, y)=='1' ? 1 :0; BiFunction<Character, Character, Integer> gi = (x,y)->charOp(booleanAnd, x, y)=='1' ? 1 :0; int p1 = pi.apply(operand1.charAt(3), operand2.charAt(3)); int g1 = gi.apply(operand1.charAt(3), operand2.charAt(3)); int p2 = pi.apply(operand1.charAt(2), operand2.charAt(2)); int g2 = gi.apply(operand1.charAt(2), operand2.charAt(2)); int p3 = pi.apply(operand1.charAt(1), operand2.charAt(1)); int g3 = gi.apply(operand1.charAt(1), operand2.charAt(1)); int p4 = pi.apply(operand1.charAt(0), operand2.charAt(0)); int g4 = gi.apply(operand1.charAt(0), operand2.charAt(0)); int c1= g1 | (p1 & c); int c2 =g2 | (p2 & g1) | (p2&p1 & c); int c3=g3|(p3 &g2) | (p3&p2&g1) | (p3&p2&p1&c); int c4=g4|(p4 & g3)|(p4&p3&g2) | (p4&p3&p2&g1) | (p4&p3&p2&p1&c); result.append(c4); result.append(fullAdder(operand1.charAt(0), operand2.charAt(0) , c3==1 ? '1' : '0').charAt(1)); result.append(fullAdder(operand1.charAt(1), operand2.charAt(1) , c2==1 ? '1' : '0').charAt(1)); result.append(fullAdder(operand1.charAt(2), operand2.charAt(2) , c1==1 ? '1' : '0').charAt(1)); result.append(fullAdder(operand1.charAt(3), operand2.charAt(3) , c).charAt(1)); return result.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 testClaAdder() { ALU alu = new ALU(); assertEquals("01011", alu.claAdder("1001", "0001", '1')); }
@Test public void testCLAAdder1(){ assertEquals("01111",ALU.claAdder("1001", "0101", '1')); }
@Test public void testCLAAdder2(){ assertEquals("10110",ALU.claAdder("1001", "1101", '0')); }