public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval placesVE) {ValueEval veText1;try {veText1 = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);} catch (EvaluationException e) {return e.getErrorEval();}String strText1 = OperandResolver.coerceValueToString(veText1);Double number = OperandResolver.parseDouble(strText1);if (number == null) {return ErrorEval.VALUE_INVALID;}if (number.longValue() < MIN_VALUE || number.longValue() > MAX_VALUE) {return ErrorEval.NUM_ERROR;}int placesNumber;if (number < 0 || placesVE == null) {placesNumber = DEFAULT_PLACES_VALUE;} else {ValueEval placesValueEval;try {placesValueEval = OperandResolver.getSingleValue(placesVE, srcRowIndex, srcColumnIndex);} catch (EvaluationException e) {return e.getErrorEval();}String placesStr = OperandResolver.coerceValueToString(placesValueEval);Double placesNumberDouble = OperandResolver.parseDouble(placesStr);if (placesNumberDouble == null) {return ErrorEval.VALUE_INVALID;}placesNumber = placesNumberDouble.intValue();if (placesNumber < 0 || placesNumber == 0) {return ErrorEval.NUM_ERROR;}}String binary = Integer.toBinaryString(number.intValue());if (binary.length() > DEFAULT_PLACES_VALUE) {binary = binary.substring(binary.length() - DEFAULT_PLACES_VALUE);}if (binary.length() > placesNumber) {return ErrorEval.NUM_ERROR;}return new StringEval(binary);}
public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval placesVE){ValueEval veText1;try{veText1 = OperandResolver.GetSingleValue(numberVE, srcRowIndex, srcColumnIndex);}catch (EvaluationException e){return e.GetErrorEval();}String strText1 = OperandResolver.CoerceValueToString(veText1);Double number = OperandResolver.ParseDouble(strText1);if (double.IsNaN(number)){return ErrorEval.VALUE_INVALID;}if (number< MinValue || number > MaxValue){return ErrorEval.NUM_ERROR;}int placesNumber;if (number < 0 || placesVE == null){placesNumber = DEFAULT_PLACES_VALUE;}else{ValueEval placesValueEval;try{placesValueEval = OperandResolver.GetSingleValue(placesVE, srcRowIndex, srcColumnIndex);}catch (EvaluationException e){return e.GetErrorEval();}String placesStr = OperandResolver.CoerceValueToString(placesValueEval);Double placesNumberDouble = OperandResolver.ParseDouble(placesStr);if (double.IsNaN( placesNumberDouble)){return ErrorEval.VALUE_INVALID;}placesNumber = (int)Math.Floor(placesNumberDouble);if (placesNumber < 0 || placesNumber == 0){return ErrorEval.NUM_ERROR;}}String binary = Convert.ToString((int)Math.Floor(number), 2);if (binary.Length > DEFAULT_PLACES_VALUE){binary = binary.Substring(binary.Length - DEFAULT_PLACES_VALUE);}if (binary.Length > placesNumber){return ErrorEval.NUM_ERROR;}return new StringEval(binary);}