* @exception IllegalActionException If there is no director.
*/
public void fire() throws IllegalActionException {
super.fire();
if (input.hasToken(0)) {
FixToken in = (FixToken) input.get(0);
int widthValue = in.fixValue().getPrecision().getNumberOfBits();
int startValue = ((IntToken) start.getToken()).intValue();
int endValue = ((IntToken) end.getToken()).intValue() + 1;
boolean lsbValue = ((StringToken) lsb.getToken()).stringValue()
.equals("LSB");
int newStartValue = (lsbValue) ? widthValue - endValue : startValue;
int newEndValue = (lsbValue) ? widthValue - startValue : endValue;
int shiftBits = (lsbValue) ? startValue : widthValue - endValue;
char[] mask = new char[widthValue];
Arrays.fill(mask, '0');
Arrays.fill(mask, newStartValue, newEndValue, '1');
BigDecimal value = new BigDecimal(in.fixValue().getUnscaledValue()
.and(new BigInteger(new String(mask), 2)).shiftRight(
shiftBits));
Precision precision = new Precision(
((Parameter) getAttribute("outputPrecision"))
.getExpression());
if ((newEndValue - newStartValue) != precision.getNumberOfBits()) {
throw new IllegalActionException(this, "Bit width of "
+ (newEndValue - newStartValue)
+ " is not equal to precision " + precision);
}
Overflow overflow = Overflow
.getName(((Parameter) getAttribute("outputOverflow"))
.getExpression().toLowerCase());
Rounding rounding = Rounding
.getName(((Parameter) getAttribute("outputRounding"))
.getExpression().toLowerCase());
FixPoint result = new FixPoint(value, new FixPointQuantization(
precision, overflow, rounding));
sendOutput(output, 0, new FixToken(result));
}
}