Example #1
0
        public override AbstractGate Clone()
        {
            TruthTable tt = new TruthTable(NumberOfInputs, Output.Length);

            for (int x = 0; x < values.GetLength(0); x++)
            {
                for (int y = 0; y < values[0].GetLength(0); y++)
                {
                    tt.values[x][y] = values[x][y];
                }
            }

            return(tt);
        }
Example #2
0
        /// <summary>
        /// Interrogate this gate with all input combinations
        /// to determine outputs.  Suitable only for single gates;
        /// do not use for ICs or any compound gate.
        /// This method is to provide an "easy" implementation of
        /// ICreateTruthTable for simple/basic gates.
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public static TruthTable DefaultTruthTable(AbstractGate g)
        {
            TruthTable tt = new TruthTable(g.NumberOfInputs, g.Output.Length);

            for (int i = 0; i < Math.Pow(2, g.NumberOfInputs); i++)
            {
                String binary = Convert.ToString(i, 2);
                binary = binary.PadLeft(g.NumberOfInputs, '0');
                bool[] vals = binary.ToCharArray().Select(x => x == '1').ToArray();
                for (int ii = 0; ii < g.NumberOfInputs; ii++)
                {
                    g[ii] = vals[ii];
                }
                for (int io = 0; io < g.Output.Length; io++)
                {
                    tt[vals, io] = g.Output[io];
                }
            }

            return(tt);
        }
Example #3
0
        /// <summary>
        /// Interrogate this gate with all input combinations
        /// to determine outputs.  Suitable only for single gates;
        /// do not use for ICs or any compound gate.
        /// This method is to provide an "easy" implementation of
        /// ICreateTruthTable for simple/basic gates.
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public static TruthTable DefaultTruthTable(AbstractGate g)
        {
            TruthTable tt = new TruthTable(g.NumberOfInputs, g.Output.Length);

            for (int i = 0; i < Math.Pow(2, g.NumberOfInputs); i++)
            {
                String binary = Convert.ToString(i, 2);
                binary = binary.PadLeft(g.NumberOfInputs, '0');
                bool[] vals = binary.ToCharArray().Select(x => x == '1').ToArray();
                for (int ii = 0; ii < g.NumberOfInputs; ii++)
                {
                    g[ii] = vals[ii];
                }
                for (int io = 0; io < g.Output.Length; io++)
                {
                    tt[vals, io] = g.Output[io];
                }


            }

            return tt;

        }
Example #4
0
        public override AbstractGate Clone()
        {
            TruthTable tt = new TruthTable(NumberOfInputs, Output.Length);
            for (int x = 0; x < values.GetLength(0); x++)
                for (int y = 0; y < values[0].GetLength(0); y++)
                    tt.values[x][y] = values[x][y];

            return tt;
        }