class 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);
		
	}

}