Click here to Skip to main content
Click here to Skip to main content

Tagged as

Truth table and simplification of a boolean expression

, 16 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
generation of Karnaugh table

Introduction 

The Karnaugh map, also known as the K-map, is a method to simplify boolean algebra.

Karnaugh maps are used to facilitate the simplification of Boolean algebra functions. Take the Boolean function described by the following truth table.

 this article, and specially the attached code, is for you.

Requirements

The reader should have basic notions of boolean algebra;Knowledge of the Quine McKluskey algorithm is optimal. Basic notions of C# are required for understanding the code.

Using of the application 

first we have to introduce the booleane expression to the textbox, this one must use only(a;b:cBig Grin | :-D ;!,+) as character, when we click the button of table truth generation the listview ll be filled by the appropriate values. in the variables fields   or sub-functions fields  or Function fields .

then, the Karnaugh button appears, and if we click it, the Karnaugh table ll be generated and filled.  

Now to simplify the expression we use tow methods the first is to simplify tow terms and return the simlified expression  

 

        <span style="color: rgb(0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono; font-size: 12px; white-space: pre; background-color: rgb(251, 237, 187);">public string simplifier1(int i,int j,int order)
        </span>{
            pos = -1;
            var dd = Form1.local_tab[i];
            var ff = new StringBuilder(dd);
            if (shift(Form1.local_tab[i], Form1.local_tab[j]) == 1)
            {
                ff.Remove(pos, 1);
                ff.Insert(pos, "-");
                lstTerms[order].SetItemChecked(i, true);
                lstTerms[order].SetItemChecked(j, true);
            }
            return ff.ToString();
        }

the socond make all simplifications possible in the Karnaugh table

    public void evaluer(int order)
        {
            int s = 0;
            for (int i = 0; i < Form1.j; i++)
            {
                for (int k = i; k < Form1.j; k++)
                {
                    simplifier1(i, k, order);
                    if ((lstTerms[order].GetItemCheckState(i) == CheckState.Checked) && (lstTerms[order].GetItemCheckState(k) == CheckState.Checked))
                    {
                        if (!tab.Contains(simplifier1(i, k, order)) && !Form1.local_tab.Contains(simplifier1(i, k, order)))
                        {
                            tab[s] = simplifier1(i, k, order);
                            lstTerms[order+1].Items.Add(tab[s]);
                            lstTerms[order+1].SetItemChecked(s, false);
                            s++;
                        }
                    }

                }


            }
            for (int i = 0; i < Form1.j; i++)
            {
                Form1.local_tab[i] = " ";
 
            }
                Form1.j = s;
                for (int i = 0; i < Form1.j; i++)
                {
                    Form1.local_tab[i] = tab[i];
                    tab[i] = " ";
                }
                if (s == 0)
                    arret = true;
        }

and that what we have as result

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Amar zaidi

Algeria Algeria
No Biography provided

Comments and Discussions

 
General[My vote of 1] Vote 1 PinmemberTonBill18-Jun-14 2:30 
GeneralMy vote of 1 PinprofessionalLostTheMarbles16-Jun-14 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 16 Jun 2014
Article Copyright 2014 by Amar zaidi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid