class ALU {

	public String floatRepresentation (String number, int eLength, int sLength) {
		long upperBound = (long) (Math.pow(2,Math.pow(2, eLength-1)) - Math.pow(2, Math.pow(2, eLength-1)-sLength-1));



		double lowerBound = Math.pow(2, -Math.pow(2, eLength)-2-sLength); 

		long shift = (long)(Math.pow(2, eLength-1)-1);
		
		boolean isNegative = number.startsWith("-");
		String firstBit = isNegative ? "1" : "0";
		
		double trueValue;
		if(number.contains("Inf")){
			return firstBit+ALU.repeatedString("1", eLength)+ALU.repeatedString("0", sLength);
		}
		try{
			trueValue = Double.parseDouble(number);
			if (Double.isNaN(trueValue)){
				throw new NumberFormatException();
			}

		}
		catch(NumberFormatException e){
			return firstBit+repeatedString("1", eLength)+repeatedString("0", sLength-1)+"1";
		}
		
		//Returns 0 if trueValue is 0
		if (Math.abs(trueValue)<=lowerBound){
			return firstBit+repeatedString("0", eLength+sLength);
		}
		
		//Returns +Inf if trueValue is greater than the upper bound
		if (trueValue>=upperBound){
			return "0"+repeatedString("1", eLength)+repeatedString("0", sLength);
		}
		
		//Returns -Inf if trueValue is less than the lower bound
		if (trueValue<=-upperBound){
			return "1"+repeatedString("1", eLength)+repeatedString("0", sLength);
		}
		
		trueValue = Math.abs(trueValue);
		
		//denormalized
		if (trueValue<Math.pow(2, -Math.pow(2, eLength-2))){
			StringBuilder result = new StringBuilder(isNegative ?"1" : "0");
			result.append(repeatedString("0", eLength));
			trueValue*=Math.pow(2,shift-1);
			while (result.length()!=1+eLength+sLength){
				trueValue *=2;
				if ((int)trueValue==1) {
					result.append("1");
					trueValue--;
				}else{
					result.append("0");
				}
			}
			return result.toString();
		}
		

		StringBuilder result = new StringBuilder(firstBit);
		
		//convert float to binary sequence
		StringBuilder binary = new StringBuilder();

		
		String integerPart = integerBinRepresentationInMinLength(String.valueOf((int)trueValue));
		binary.append(integerPart).append(".");
		
		double decFloatPart = trueValue - (int)trueValue;
		
		while(binary.length()<=sLength+3){ //sLength+2 preserves the required number length. sLength with 0 and dot
			decFloatPart *=2;
			if ((int)decFloatPart==1){
				binary.append("1");
				decFloatPart--;
			}else{
				binary.append("0");
			}
		}
		
		int firstOneIndex = binary.indexOf("1");

		//if no 1 exists, indicates the value can be 0
		if (firstOneIndex==-1){
			return result.append(repeatedString("0", sLength+eLength)).toString();
		}
		
		//gets the index of dot. Appends if not exist.
		int dotIndex = binary.indexOf(".");
		if (dotIndex==-1){
			binary.append(".");
			dotIndex = binary.length()-1;
		}

		long exponent =shift;
		if (dotIndex>firstOneIndex){//1001.111, firstOneIndex=0, dotIndex=5, should be 4
			exponent += dotIndex-firstOneIndex-1; 
		}else{ //0.000101, firstOneIndex=5, dotIndex=1, should be -4
			exponent += dotIndex-firstOneIndex;
		}
		String exponentPart = integerRepresentation(String.valueOf(exponent), eLength);
		result.append(exponentPart);

		StringBuilder mantissa = new StringBuilder(binary.substring(firstOneIndex+1).replace(".",""));
		mantissa.append(repeatedString("0", sLength-mantissa.length()));
		result.append(mantissa);

		result.setLength(1+eLength+sLength); //preserves length

		return result.toString();
	}

}