Package com.cburch.logisim.std.gates

Source Code of com.cburch.logisim.std.gates.EvenParityGate

/* Copyright (c) 2010, Carl Burch. License information is located in the
* com.cburch.logisim.Main source code and at www.cburch.com/logisim/. */

package com.cburch.logisim.std.gates;

import com.cburch.logisim.analyze.model.Expression;
import com.cburch.logisim.analyze.model.Expressions;
import com.cburch.logisim.data.Value;
import com.cburch.logisim.instance.InstancePainter;
import com.cburch.logisim.instance.InstanceState;

class EvenParityGate extends AbstractGate {
  public static EvenParityGate FACTORY = new EvenParityGate();

  private EvenParityGate() {
    super("Even Parity", Strings.getter("evenParityComponent"));
    setRectangularLabel("2k");
    setIconNames("parityEvenGate.gif");
  }

  @Override
  public void paintIconShaped(InstancePainter painter) {
    paintIconRectangular(painter);
  }

  @Override
  protected void paintShape(InstancePainter painter, int width, int height) {
    paintRectangular(painter, width, height);
  }

  @Override
  protected void paintDinShape(InstancePainter painter, int width, int height,
      int inputs) {
    paintRectangular(painter, width, height);
  }

  @Override
  protected Value computeOutput(Value[] inputs, int numInputs, InstanceState state) {
    return GateFunctions.computeOddParity(inputs, numInputs).not();
  }

  @Override
  protected Expression computeExpression(Expression[] inputs, int numInputs) {
    Expression ret = inputs[0];
    for (int i = 1; i < numInputs; i++) {
      ret = Expressions.xor(ret, inputs[i]);
    }
    return Expressions.not(ret);
  }

  @Override
  protected Value getIdentity() { return Value.FALSE; }
}
TOP

Related Classes of com.cburch.logisim.std.gates.EvenParityGate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.