LogicGates/eu.heili/ExorGate.java

25 lines
739 B
Java
Raw Normal View History

public class ExorGate extends LogicGate {
2020-04-14 09:29:26 +00:00
public ExorGate(final int inputnr) {
super(inputnr);
if (inputnr > 2)
throw (new TooManyInputsException());
}
2020-04-14 09:29:26 +00:00
public ExorGate(final DigitalInput... inputvals) {
super(inputvals);
if (inputvals.length > 2)
throw (new TooManyInputsException());
}
@Override
public boolean getOutput() {
boolean first = getInput(0).getValue();
for (int i = 1; i < getInputNumber(); i++) {
if (getInput(i).getValue() != first)
return true; // if there is one change return true
first = getInput(i).getValue();
}
return false; // all values are the same...
}
2020-04-13 09:14:15 +00:00
}