/// <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); }
/// <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; }