Пример #1
0
        /// <summary>
        /// 輸出真值表
        /// </summary>
        /// <returns></returns>
        public static string GetTruthTable()
        {
            string Result = string.Empty;

            Result = "Truth table:\n";
            PrivtFieldName(ref Result);

            // 運行次數:2的N次方,N為Input pin數量
            for (int i = 0; i < Math.Pow(2, (iPins.Length - 1)); i++)
            {
                int k = i;
                // 10進制轉2進制,並送入電路的Inputs
                for (int j = 0; j < iPins.Length - 1; j++)
                {
                    iPins[((iPins.Length - 1) - j)].iPins = (Convert.ToBoolean(k % 2));
                    k /= 2;
                }
                // 輸出當前input的訊號 0 0 1
                for (int j = 1; j < iPins.Length; j++)
                {
                    Result += (Convert.ToInt32(iPins[j].iPins) + " ");
                }

                // 輸出結果
                Result += "|";
                foreach (dynamic OutputValue in oPins)
                {
                    Result += (" " + Convert.ToInt32(OutputValue.GetOutput()));
                }


                Result += ("\n");
            }
            return(Result);
        }