Sub topic 8
Karnaugh Map Layout and Gray Code
Prerequisites and purpose
This chapter assumes that you can convert between binary and decimal, read Boolean variables, and recognize AND, OR, and NOT operations. You should also know that a minterm is one input combination written as a product of literals.
A Karnaugh map, or K-map, is a visual arrangement of truth-table rows. It places neighboring input combinations next to one another so that Boolean terms differing in one variable can be combined.
Why Gray code is used
Ordinary binary order is:
00011011
The transition from 01 to 10 changes two bits. Such entries should not be adjacent when simplifying a Boolean function.
K-maps use Gray-code order:
00011110
Each pair of consecutive entries differs in exactly one bit.
| Position | Gray-code value | Changed bit from previous value |
|---|---|---|
| 1 | `00` | — |
| 2 | `01` | second bit |
| 3 | `11` | first bit |
| 4 | `10` | second bit |
The first and last values are also adjacent because 00 and 10 differ in one bit. Therefore, Gray-code order forms a cycle.
K-map dimensions
For a function with \(n\) variables, the map has \(2^n\) cells. Variables are divided between row labels and column labels.
A two-variable map has four cells. A three-variable map commonly uses one variable for rows and two variables for columns. A four-variable map commonly uses two variables for rows and two variables for columns.
For four variables \(A,B,C,D\), use Gray-code labels on both axes:
| \(AB \backslash CD\) | `00` | `01` | `11` | `10` |
|---|---|---|---|---|
| `00` | \(m_0\) | \(m_1\) | \(m_3\) | \(m_2\) |
| `01` | \(m_4\) | \(m_5\) | \(m_7\) | \(m_6\) |
| `11` | \(m_{12}\) | \(m_{13}\) | \(m_{15}\) | \(m_{14}\) |
| `10` | \(m_8\) | \(m_9\) | \(m_{11}\) | \(m_{10}\) |
To locate a minterm, write its four-bit binary representation as \(ABCD\), then find its row using \(AB\) and its column using \(CD\). For example, \(m_{10}=1010\), so it belongs in row 10 and column 10.
Adjacency and map edges
Two cells are adjacent when their labels differ in exactly one variable. Adjacency is horizontal or vertical, never diagonal.
The map wraps around:
- The first and last columns are adjacent.
- The first and last rows are adjacent.
- The four corner cells are mutually connected through these wraparound edges.
This arrangement lets a group cross an edge without breaking the Boolean simplification. Every valid group contains \(1, 2, 4, 8,\ldots\) cells.
Exercise
Exercise
In a four-variable K-map, which minterms are adjacent to m10?
Show answer
m8, m11, m14, and m2. They differ from 1010 in exactly one bit, including m2 through the wraparound between the first and last rows.