Пример #1
0
        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;
        }
Пример #2
0
        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;
        }
Пример #3
0
        // full addr operation is accomplished by using 2 half addrs and or gate for the output carrier
        public FullAdder()
        {
            // initilaize the gates
            CarryInput       = new Wire();
            CarryOutput      = new Wire();
            first_half_addr  = new HalfAdder();
            second_half_addr = new HalfAdder();
            or_op            = new OrGate();

            //connecting the first addr
            first_half_addr.ConnectInput1(Input1);
            first_half_addr.ConnectInput2(Input2);

            //connecting the second addr
            second_half_addr.ConnectInput1(first_half_addr.Output);
            second_half_addr.ConnectInput2(CarryInput);

            //or_op for the carry output
            or_op.ConnectInput1(second_half_addr.CarryOutput);
            or_op.ConnectInput2(first_half_addr.CarryOutput);

            //connecting the outputs
            Output.ConnectInput(second_half_addr.Output);
            CarryOutput.ConnectInput(or_op.Output);
        }
Пример #4
0
 //iterates each bit of the 2 inputs and making or operation using "OR" gate - saves the output in Output
 public BitwiseOrGate(int iSize)
     : base(iSize)
 {
     for (int bit = 0; bit < iSize; bit++)
     {
         or_gate_per_bit = new OrGate();
         or_gate_per_bit.ConnectInput1(Input1[bit]);
         or_gate_per_bit.ConnectInput2(Input2[bit]);
         Output[bit].ConnectInput(or_gate_per_bit.Output);
     }
 }
Пример #5
0
        private Wire calc(Wire input1, Wire input2, int wireNum)
        {
            orGate = new OrGate();
            orGate.ConnectInput1(input1);
            orGate.ConnectInput2(input2);

            if (wireNum < 0)
            {
                return(orGate.Output);
            }
            return(calc(orGate.Output, this.m_wsInput[wireNum], wireNum - 1));
        }
Пример #6
0
        public BitwiseOrGate(int iSize)
            : base(iSize)
        {
            or = new OrGate();

            for (int i = 0; i < Size; i++)
            {
                or.ConnectInput1(Input1[i]);
                or.ConnectInput2(Input2[i]);

                Output[i].ConnectInput(or.Output);
                or = new OrGate();
            }
        }
Пример #7
0
 public XorGate()
 {
     //your code here
     m_gAAndNotB = new AAndNotBGate();
     m_gNotAAndB = new AAndNotBGate();
     m_gOr       = new OrGate();
     m_gAAndNotB.ConnectInput1(Input1);
     m_gAAndNotB.ConnectInput2(Input2);
     m_gNotAAndB.ConnectInput1(Input2);
     m_gNotAAndB.ConnectInput2(Input1);
     m_gOr.ConnectInput1(m_gAAndNotB.Output);
     m_gOr.ConnectInput2(m_gNotAAndB.Output);
     Output = m_gOr.Output;
 }
Пример #8
0
        //making or operation for  2 consecutive bits(wires) until the  last bit. first bit is constant - 0
        public MultiBitOrGate(int iInputCount)
            : base(iInputCount)
        {
            size_of_wire = iInputCount;
            result       = new Wire();
            result.Value = 0;

            for (int bit = 0; bit < iInputCount; bit++)
            {
                or_operator = new OrGate();
                or_operator.ConnectInput1(result);
                or_operator.ConnectInput2(m_wsInput[bit]);
                result = or_operator.Output;
            }
            Output = result;
        }
Пример #9
0
 public FullAdder()
 {
     CarryInput = new Wire();
     //your code here
     CarryOutput = new Wire();
     ha1         = new HalfAdder();
     ha2         = new HalfAdder();
     or          = new OrGate();
     ha2.ConnectInput1(ha1.Output);
     ha2.ConnectInput2(CarryInput);
     or.ConnectInput1(ha1.CarryOutput);
     or.ConnectInput2(ha2.CarryOutput);
     Input1      = ha1.Input1;
     Input2      = ha1.Input2;
     CarryOutput = or.Output;
     Output      = ha2.Output;
 }
Пример #10
0
        //your code here


        public FullAdder()
        {
            CarryInput = new Wire();
            //your code here
            HalfAdder ha1 = new HalfAdder();
            HalfAdder ha2 = new HalfAdder();
            OrGate    or  = new OrGate();

            ha1.ConnectInput1(Input1);
            ha1.ConnectInput2(Input2);
            ha2.ConnectInput2(CarryInput);
            ha2.ConnectInput1(ha1.Output);
            or.ConnectInput2(ha1.CarryOutput);
            or.ConnectInput1(ha2.CarryOutput);
            Output      = ha2.Output;
            CarryOutput = or.Output;
        }
Пример #11
0
        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;
        }
Пример #12
0
        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;
        }
Пример #13
0
        //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;
        }
Пример #14
0
 public AndGate()
 {
     //init the gates
     m_gOR        = new OrGate();
     m_gNotInput1 = new NotGate();
     m_gNotInput2 = new NotGate();
     m_gNotOutput = new NotGate();
     //wire the inputs to the not gates
     m_gNotInput1.ConnectInput(Input1);
     m_gNotInput2.ConnectInput(Input2);
     //connect the or gate
     m_gOR.ConnectInput1(m_gNotInput1.Output);
     m_gOR.ConnectInput2(m_gNotInput2.Output);
     //connect the not on the output
     m_gNotOutput.ConnectInput(m_gOR.Output);
     //set the  output of the and gate
     Output = m_gNotOutput.Output;
 }
Пример #15
0
        public FullAdder()
        {
            CarryInput = new Wire();

            //your code here
            ha  = new HalfAdder();
            ha2 = new HalfAdder();
            og  = new OrGate();

            ha.ConnectInput1(Input1);
            ha.ConnectInput2(Input2);
            ha2.ConnectInput1(ha.Output);
            ha2.ConnectInput2(CarryInput);
            og.ConnectInput1(ha2.CarryOutput);
            og.ConnectInput2(ha.CarryOutput);

            Output      = ha2.Output;
            CarryOutput = og.Output;
        }
Пример #16
0
        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;
        }
Пример #17
0
        public MultiBitOrGate(int iInputCount)
            : base(iInputCount)
        {
            or = new OrGate();
            or.ConnectInput1(m_wsInput[0]);
            or.ConnectInput2(m_wsInput[1]);
            Wire temp = or.Output;

            for (int i = 2; i < iInputCount; i++)
            {
                or = new OrGate();

                or.ConnectInput1(temp);
                or.ConnectInput2(m_wsInput[i]);

                temp = or.Output;
            }

            Output = temp;
        }
Пример #18
0
        public FullAdder()
        {
            CarryInput  = new Wire();
            CarryOutput = new Wire();
            half1       = new HalfAdder();
            half2       = new HalfAdder();
            or          = new OrGate();

            half1.ConnectInput1(Input1);
            half1.ConnectInput2(Input2);


            half2.ConnectInput1(CarryInput);
            half2.ConnectInput2(half1.Output);

            or.ConnectInput1(half1.CarryOutput);
            or.ConnectInput2(half2.CarryOutput);

            CarryOutput.ConnectInput(or.Output);
            Output.ConnectInput(half2.Output);
        }
Пример #19
0
        public FullAdder()
        {
            CarryInput  = new Wire();
            CarryOutput = new Wire();

            var halfAdd1 = new HalfAdder();
            var halfAdd2 = new HalfAdder();
            var gOr      = new OrGate();

            halfAdd2.ConnectInput2(CarryInput);
            halfAdd2.ConnectInput1(halfAdd1.Output);

            gOr.ConnectInput1(halfAdd1.CarryOutput);
            gOr.ConnectInput2(halfAdd2.CarryOutput);

            Input1 = halfAdd1.Input1;
            Input2 = halfAdd1.Input2;

            CarryOutput = gOr.Output;
            Output      = halfAdd2.Output;
        }
Пример #20
0
        public FullAdder()
        {
            CarryInput = new Wire();
            //your code here

            CarryOutput = new Wire();

            m_gHf = new HalfAdder();
            m_gHf.ConnectInput1(Input1);
            m_gHf.ConnectInput2(Input2);

            m_gHfCin = new HalfAdder();
            m_gHfCin.ConnectInput1(m_gHf.Output);
            m_gHfCin.ConnectInput2(CarryInput);
            Output.ConnectInput(m_gHfCin.Output);

            m_gOrCout = new OrGate();
            m_gOrCout.ConnectInput1(m_gHf.CarryOutput);
            m_gOrCout.ConnectInput2(m_gHfCin.CarryOutput);
            CarryOutput.ConnectInput(m_gOrCout.Output);
        }
Пример #21
0
        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;
        }
Пример #22
0
        //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;
        }
Пример #23
0
        public override bool TestGate()
        {
            BitwiseOrGate bwog;
            OrGate        m_gLocalOr;

            for (int j = 0; j < Math.Pow(2, Size); j++)
            {
                bwog = new BitwiseOrGate(Size);
                bwog.Input1.ConnectInput(InitTestVariables(j));
                bwog.Input2.ConnectInput(InitRandTestVar(Size));

                for (int i = 0; i < Size; i++)
                {
                    m_gLocalOr = new OrGate();
                    m_gLocalOr.ConnectInput1(bwog.Input1[i]);
                    m_gLocalOr.ConnectInput2(bwog.Input2[i]);
                    if (bwog.Input1[i].Value == 1 || bwog.Input2[i].Value == 1)
                    {
                        if (m_gLocalOr.Output.Value != 1 || bwog.m_gOrGate[i].Output.Value != 1)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (m_gLocalOr.Output.Value != 0)
                        {
                            return(false);
                        }
                    }
                }
                // UNCOMMENT THIS LINES TO SEE THE DEBUG PRINT
                //System.Console.WriteLine("    Testing input1 " + " -> " + WStoString(bwog.Input1));
                //System.Console.WriteLine("    Testing input2 " + " -> " + WStoString(bwog.Input2));
                //System.Console.WriteLine("    Testing output " + " -> " + WStoString(bwog.Output));
            }
            return(true);
        }
Пример #24
0
        // accoplish using 2 "AND", "OR" and "NOT" gates,
        // first connect input 1 and "NOT" control bit to "AND" gate 1, then connect input 2 and control bit to "AND" gate 2
        // lastly connect the outputs of "AND" gates to "OR" gate
        public MuxGate()
        {
            ControlInput = new Wire();

            // initilaize the gates
            and_input1             = new AndGate();
            and_input2             = new AndGate();
            not_contolinput_input1 = new NotGate();
            or_output = new OrGate();

            //step 1
            not_contolinput_input1.ConnectInput(ControlInput);
            and_input1.ConnectInput1(Input1);
            and_input1.ConnectInput2(not_contolinput_input1.Output);

            //step 2
            and_input2.ConnectInput1(Input2);
            and_input2.ConnectInput2(ControlInput);

            //step 3
            or_output.ConnectInput1(and_input1.Output);
            or_output.ConnectInput2(and_input2.Output);
            Output = or_output.Output;
        }
Пример #25
0
        public MuxGate()
        {
            ControlInput = new Wire();

            not  = new NotGate();
            and1 = new AndGate();
            and2 = new AndGate();
            or   = new OrGate();

            not.ConnectInput(ControlInput);

            and1.ConnectInput1(not.Output);
            //and1.ConnectInput2();

            and2.ConnectInput1(ControlInput);
            //and2.ConnectInput2(Input2);

            Input1 = and1.Input2;
            Input2 = and2.Input2;

            or.ConnectInput1(and1.Output);
            or.ConnectInput2(and2.Output);
            Output = or.Output;
        }