public Demux() { Input = new Wire(); Control = new Wire(); Output1 = new Wire(); Output2 = new Wire(); //your code here m_gAnd1 = new AndGate(); m_gAnd2 = new AndGate(); m_gNot = new NotGate(); Output1.Value = 0; Output2.Value = 0; m_gNot.ConnectInput(Control); m_gAnd1.ConnectInput1(Input); m_gAnd1.ConnectInput2(m_gNot.Output); m_gAnd2.ConnectInput1(Input); m_gAnd2.ConnectInput2(Control); Output1 = m_gAnd1.Output; Output2 = m_gAnd2.Output; }
public XorGate() { //init the gates Wire wire1 = new Wire(); //for A, first side Wire wire2 = new Wire(); //for B, second side m_gNot1 = new NotGate(); //for B, first side m_gNot2 = new NotGate(); //for A, second side m_gAnd1 = new AndGate(); //first side m_gAnd2 = new AndGate(); //second side m_gOr = new OrGate(); //connect the gates m_gOr.ConnectInput1(m_gAnd1.Output); m_gOr.ConnectInput2(m_gAnd2.Output); m_gAnd1.ConnectInput1(wire1); m_gNot1.ConnectInput(wire2); m_gAnd1.ConnectInput2(m_gNot1.Output); m_gNot2.ConnectInput(wire1); m_gAnd2.ConnectInput1(m_gNot2.Output); m_gAnd2.ConnectInput2(wire2); //set the inputs and the output of the or gate Output = m_gOr.Output; Input1 = wire1; Input2 = wire2; }
public MuxGate() {//init ControlInput = new Wire(); Wire a = new Wire(); Wire b = new Wire(); and1 = new AndGate(); and2 = new AndGate(); or = new OrGate(); not = new NotGate(); //connect or.ConnectInput1(and1.Output); or.ConnectInput2(and2.Output); and1.ConnectInput1(ControlInput); and1.ConnectInput2(b); and2.ConnectInput1(not.Output); not.ConnectInput(ControlInput); and2.ConnectInput2(a); /* or.ConnectInput1(and1.Output); * or.ConnectInput2(and2.Output); * and1.ConnectInput1(ControlInput); * and1.ConnectInput1(b); * not.ConnectInput(ControlInput); * and2.ConnectInput1(not.Output); * and2.ConnectInput2(a); */ //input\output Input1 = a; Input2 = b; Output = or.Output; }
// accoplish using 2 "AND" and "NOT" gates, // first connect input and "NOT" control bit to "AND" gate 1, then connect input and control bit to "AND" gate 2 // lastly connect the outputs public Demux() { Input = new Wire(); Control = new Wire(); Output1 = new Wire(); Output2 = new Wire(); // initilaize the gates and_output1 = new AndGate(); and_output2 = new AndGate(); not_contolinput_input1 = new NotGate(); //step 1 not_contolinput_input1.ConnectInput(Control); and_output1.ConnectInput1(Input); and_output1.ConnectInput2(not_contolinput_input1.Output); //step 2 and_output2.ConnectInput1(Input); and_output2.ConnectInput2(Control); //step 3 Output1 = and_output1.Output; Output2 = and_output2.Output; }
public MuxGate() { ControlInput = new Wire(); //Init the variables m_gAnd1 = new AndGate(); m_gAnd2 = new AndGate(); m_gAnd3 = new AndGate(); m_gNot = new NotGate(); m_gmOr = new MultiBitOrGate(3); m_ws = new WireSet(3); //Connect the wires m_gNot.ConnectInput(ControlInput); m_gAnd1.ConnectInput1(Input1); m_gAnd1.ConnectInput2(Input2); m_gAnd2.ConnectInput1(Input2); m_gAnd2.ConnectInput2(ControlInput); m_gAnd3.ConnectInput1(Input1); m_gAnd3.ConnectInput2(m_gNot.Output); m_ws[0].ConnectInput(m_gAnd1.Output); m_ws[1].ConnectInput(m_gAnd2.Output); m_ws[2].ConnectInput(m_gAnd3.Output); m_gmOr.ConnectInput(m_ws); Output = m_gmOr.Output; }
public AAndNotBGate() { m_gNot = new NotGate(); m_gAnd = new AndGate(); m_gNot.ConnectInput(Input2); m_gAnd.ConnectInput1(Input1); m_gAnd.ConnectInput2(m_gNot.Output); Output = m_gAnd.Output; }
//iterates each bit of the 2 inputs and making or operation using "OR" gate - saves the output in Output public BitwiseAndGate(int iSize) : base(iSize) { for (int bit = 0; bit < iSize; bit++) { and_gate_per_bit = new AndGate(); and_gate_per_bit.ConnectInput1(Input1[bit]); and_gate_per_bit.ConnectInput2(Input2[bit]); Output[bit].ConnectInput(and_gate_per_bit.Output); } }
public HalfAdder() { //your code here ag = new AndGate(); xog = new XorGate(); ag.ConnectInput1(Input1); ag.ConnectInput2(Input2); xog.ConnectInput1(Input1); xog.ConnectInput2(Input2); CarryOutput = ag.Output; Output = xog.Output; }
//nand gate is defines as not-AND gate, the procedure is completed using the AND,NOT gates. public NAndGate() { and_input = new AndGate(); not_output = new NotGate(); and_input.ConnectInput1(Input1); and_input.ConnectInput2(Input2); not_output.ConnectInput(and_input.Output); Output = not_output.Output; }
private Wire calc(Wire input1, Wire input2, int wireNum) { andGate = new AndGate(); andGate.ConnectInput1(input1); andGate.ConnectInput2(input2); if (wireNum < 0) { return(andGate.Output); } return(calc(andGate.Output, this.m_wsInput[wireNum], wireNum - 1)); }
//your code here public HalfAdder() { //your code here XorGate xor = new XorGate(); AndGate and = new AndGate(); xor.ConnectInput1(Input1); xor.ConnectInput2(Input2); and.ConnectInput1(Input2); and.ConnectInput2(Input1); Output = xor.Output; CarryOutput = and.Output; }
public BitwiseAndGate(int iSize) : base(iSize) { and = new AndGate(); for (int i = 0; i < Size; i++) { and.ConnectInput1(Input1[i]); and.ConnectInput2(Input2[i]); Output[i].ConnectInput(and.Output); and = new AndGate(); } }
public HalfAdder() { CarryOutput = new Wire(); xor = new XorGate(); and = new AndGate(); xor.ConnectInput1(Input1); xor.ConnectInput2(Input2); and.ConnectInput1(Input1); and.ConnectInput2(Input2); CarryOutput.ConnectInput(and.Output); Output.ConnectInput(xor.Output); }
public HalfAdder() { //your code here m_gXor = new XorGate(); m_gAnd = new AndGate(); m_gXor.ConnectInput1(Input1); m_gXor.ConnectInput2(Input2); Output.ConnectInput(m_gXor.Output); m_gAnd.ConnectInput1(Input1); m_gAnd.ConnectInput2(Input2); CarryOutput = new Wire(); CarryOutput.ConnectInput(m_gAnd.Output); }
//making and operation for 2 consecutive bits(wires) until the last bit. first bit is constant - 1 public MultiBitAndGate(int iInputCount) : base(iInputCount) { size_of_wire = iInputCount; result = new Wire(); result.Value = 1; for (int bit = 0; bit < iInputCount; bit++) { and_operator = new AndGate(); and_operator.ConnectInput1(result); and_operator.ConnectInput2(m_wsInput[bit]); result = and_operator.Output; } Output = result; }
public OrGate() { //init the gates m_gNot1 = new NotGate(); //outside the parentheses m_gNot2 = new NotGate(); //a m_gNot3 = new NotGate(); //b m_gAnd = new AndGate(); //connect the gates m_gAnd.ConnectInput1(m_gNot2.Output); m_gAnd.ConnectInput2(m_gNot3.Output); m_gNot1.ConnectInput(m_gAnd.Output); //set the inputs and the output of the or gate Output = m_gNot1.Output; Input1 = m_gNot2.Input; Input2 = m_gNot3.Input; }
public MuxGate() { ControlInput = new Wire(); m_gNot = new NotGate(); m_gAnd1 = new AndGate(); m_gAnd2 = new AndGate(); m_gOr = new OrGate(); m_gAnd1.ConnectInput1(m_gNot.Output); m_gOr.ConnectInput1(m_gAnd1.Output); m_gOr.ConnectInput2(m_gAnd2.Output); m_gNot.ConnectInput(ControlInput); m_gAnd2.ConnectInput1(ControlInput); Input1 = m_gAnd1.Input2; Input2 = m_gAnd2.Input2; Output = m_gOr.Output; }
public XorGate() { or = new OrGate(); NAnd = new NAndGate(); and = new AndGate(); Input1 = or.Input1; Input2 = or.Input2; NAnd.ConnectInput1(Input1); NAnd.ConnectInput2(Input2); and.ConnectInput1(or.Output); and.ConnectInput2(NAnd.Output); Output = and.Output; }
public XorGate() { m_gNand = new NAndGate(); m_gOr = new OrGate(); m_gAnd = new AndGate(); m_gOr.ConnectInput1(Input1); m_gOr.ConnectInput2(Input2); m_gNand.ConnectInput1(Input1); m_gNand.ConnectInput2(Input2); m_gAnd.ConnectInput1(m_gOr.Output); m_gAnd.ConnectInput2(m_gNand.Output); Output = m_gAnd.Output; }
//Xor gate is possible to get by combining with and gate the results of the nand and or gates. public XorGate() { nand_input = new NAndGate(); or_input = new OrGate(); and_output = new AndGate(); nand_input.ConnectInput1(Input1); nand_input.ConnectInput2(Input2); or_input.ConnectInput1(Input1); or_input.ConnectInput2(Input2); and_output.ConnectInput1(nand_input.Output); and_output.ConnectInput2(or_input.Output); Output = and_output.Output; }
//your code here public Demux() { Input = new Wire(); Control = new Wire(); //init AndGate and1 = new AndGate(); AndGate and2 = new AndGate(); NotGate not = new NotGate(); and1.ConnectInput1(Input); and2.ConnectInput2(Input); not.ConnectInput(Control); and1.ConnectInput2(not.Output); and2.ConnectInput1(Control); Output1 = and1.Output; Output2 = and2.Output; }
public Demux() { Input = new Wire(); Control = new Wire(); m_gAnd1 = new AndGate(); m_gAnd2 = new AndGate(); m_gNot = new NotGate(); m_gNot.ConnectInput(Control); m_gAnd1.ConnectInput1(m_gNot.Output); m_gAnd1.ConnectInput2(Input); m_gAnd2.ConnectInput1(Control); m_gAnd2.ConnectInput2(Input); Output1 = m_gAnd1.Output; Output2 = m_gAnd2.Output; }
// creating the halfadder by using the "xor" and "and gates" for the output and the carry public HalfAdder() { // initilaize the gates CarryOutput = new Wire(); xor_op = new XorGate(); and_op = new AndGate(); //xor operation for the sum output xor_op.ConnectInput1(Input1); xor_op.ConnectInput2(Input2); //and operation for the carry output and_op.ConnectInput1(Input1); and_op.ConnectInput2(Input2); //connecting outputs Output.ConnectInput(xor_op.Output); CarryOutput.ConnectInput(and_op.Output); }
public XorGate() { //your code here m_gAnd = new AndGate(); m_gNand = new NAndGate(); m_gOr = new OrGate(); m_gAnd.ConnectInput1(m_gNand.Output); m_gAnd.ConnectInput2(m_gOr.Output); Input1 = m_gOr.Input1; Input2 = m_gOr.Input2; m_gNand.ConnectInput1(Input1); m_gNand.ConnectInput2(Input2); Output = m_gAnd.Output; }
public MuxGate() { ControlInput = new Wire(); m_gAndX = new AndGate(); m_gAndY = new AndGate(); m_gOr = new OrGate(); m_gNotC = new NotGate(); m_gAndY.ConnectInput1(ControlInput); m_gAndY.ConnectInput2(Input2); m_gNotC.ConnectInput(ControlInput); m_gAndX.ConnectInput2(m_gNotC.Output); m_gAndX.ConnectInput1(Input1); m_gOr.ConnectInput1(m_gAndX.Output); m_gOr.ConnectInput2(m_gAndY.Output); Output = m_gOr.Output; }
public MultiBitAndGate(int iInputCount) : base(iInputCount) { and = new AndGate(); and.ConnectInput1(m_wsInput[0]); and.ConnectInput2(m_wsInput[1]); Wire temp = and.Output; for (int i = 2; i < m_wsInput.Size; i++) { and = new AndGate(); and.ConnectInput1(temp); and.ConnectInput2(m_wsInput[i]); temp = and.Output; } Output = temp; }
//your code here public Demux() { Input = new Wire(); var mGAnd1 = new AndGate(); var mGAnd2 = new AndGate(); var mGNot1 = new NotGate(); Control = new Wire(); mGNot1.ConnectInput(Control); mGAnd2.ConnectInput1(Input); mGAnd2.ConnectInput2(Control); mGAnd1.ConnectInput1(Input); mGAnd1.ConnectInput2(mGNot1.Output); Output1 = mGAnd1.Output; Output2 = mGAnd2.Output; }
public MuxGate() { var mGAnd1 = new AndGate(); var mGAnd2 = new AndGate(); var mGNot1 = new NotGate(); var mGOr = new OrGate(); ControlInput = new Wire(); mGNot1.ConnectInput(ControlInput); mGAnd2.ConnectInput1(Input2); mGAnd2.ConnectInput2(ControlInput); mGAnd1.ConnectInput1(Input1); mGAnd1.ConnectInput2(mGNot1.Output); mGOr.ConnectInput1(mGAnd1.Output); mGOr.ConnectInput2(mGAnd2.Output); Output = mGOr.Output; }
//A XOR B = (A ^ ~B)U(~A ^ B) public XorGate() { //init the gates var mGNot1 = new NotGate(); var mGNot2 = new NotGate(); var mGAnd1 = new AndGate(); var mGAnd2 = new AndGate(); var mGOr = new OrGate(); //wire mGAnd1.ConnectInput1(mGNot1.Output); mGAnd1.ConnectInput2(mGNot2.Input); mGAnd2.ConnectInput1(mGNot1.Input); mGAnd2.ConnectInput2(mGNot2.Output); mGOr.ConnectInput1(mGAnd1.Output); mGOr.ConnectInput2(mGAnd2.Output); //set the inputs and the output of the xor gate Output = mGOr.Output; Input1 = mGNot1.Input; Input2 = mGNot2.Input; }
public override bool TestGate() { BitwiseAndGate bwag; AndGate m_gLocalAnd; for (int j = 0; j < Math.Pow(2, Size); j++) { bwag = new BitwiseAndGate(Size); bwag.Input1.ConnectInput(InitTestVariables(j)); bwag.Input2.ConnectInput(InitRandTestVar(Size)); for (int i = 0; i < Size; i++) { m_gLocalAnd = new AndGate(); m_gLocalAnd.ConnectInput1(bwag.Input1[i]); m_gLocalAnd.ConnectInput2(bwag.Input2[i]); if (bwag.Input1[i].Value == bwag.Input2[i].Value && bwag.Input2[i].Value == 1) { if (m_gLocalAnd.Output.Value != 1 || bwag.m_gAnd[i].Output.Value != m_gLocalAnd.Output.Value) { return(false); } } else { if (m_gLocalAnd.Output.Value != 0) { return(false); } } } // UNCOMMENT THIS LINES TO SEE THE DEBUG PRINT //System.Console.WriteLine(" Testing input1 " + " -> " + WStoString(bwag.Input1)); //System.Console.WriteLine(" Testing input2 " + " -> " + WStoString(bwag.Input2)); //System.Console.WriteLine(" Testing output " + " -> " + WStoString(bwag.Output)); } return(true); }