Click here to Skip to main content
13,801,188 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 16 Jun 2014
Licenced CPOL

Truth Table and Simplification of a Boolean Expression

, 30 Oct 2016
Rate this:
Please Sign up or sign in to vote.
Generation of Karnaugh table


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.

                                                               Figure1 truth table  [1]

This article, and especially the attached code, is for those want to know how KARNAUGH table reduice an algebra expression.


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 boolean expression in the textbox. This one must use only (a;b:c:d;!,+) characters, then we click the button of table truth generation to fill our listview by the appropriate values.

Once the truth table is filled, we can process to generation of the Karnaugh table by clicking the button named Kanaugh.

To simplify the expression in codesource, we use two methods, the first is to simplify two terms and return the simplified expression.

 public string simplifier1(int i,int j,int order)
    int 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 second makes 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].SetItemChecked(s, false);
        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;

This is what we have as result:

Reference an Attribution 



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


About the Author

Amar zaidi
Algeria Algeria
No Biography provided

You may also be interested in...

Comments and Discussions

PraiseThanks Pin
Phil Ouellette29-Oct-16 9:42
memberPhil Ouellette29-Oct-16 9:42 
GeneralRe: Thanks Pin
Amar zaidi30-Oct-16 11:51
memberAmar zaidi30-Oct-16 11:51 
BugMy vote of 2 Pin
Philippe Mori28-Oct-16 4:19
memberPhilippe Mori28-Oct-16 4:19 
GeneralRe: My vote of 2 Pin
Amar zaidi30-Oct-16 3:06
memberAmar zaidi30-Oct-16 3:06 
GeneralMissing attribution for image Pin
Jochen Arndt28-Oct-16 3:34
mvpJochen Arndt28-Oct-16 3:34 
GeneralCannot Download the ZIP File Pin
Member 1004250111-Oct-16 5:59
memberMember 1004250111-Oct-16 5:59 
GeneralRe: Cannot Download the ZIP File Pin
ronen4428-Oct-16 20:30
memberronen4428-Oct-16 20:30 
Questiondownload Pin
TerryM7928-Feb-15 9:19
memberTerryM7928-Feb-15 9:19 
AnswerRe: download Pin
Amar zaidi30-Oct-16 12:20
memberAmar zaidi30-Oct-16 12:20 
General[My vote of 1] Vote 1 Pin
TonBill18-Jun-14 3:30
memberTonBill18-Jun-14 3:30 
GeneralRe: [My vote of 1] Vote 1 Pin
Amar zaidi30-Oct-16 12:22
memberAmar zaidi30-Oct-16 12:22 
GeneralMy vote of 1 Pin
LostTheMarbles16-Jun-14 3:48
professionalLostTheMarbles16-Jun-14 3:48 
GeneralRe: My vote of 1 Pin
Amar zaidi30-Oct-16 12:23
memberAmar zaidi30-Oct-16 12:23 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.181215.1 | Last Updated 30 Oct 2016
Article Copyright 2014 by Amar zaidi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid