Skip to content

Gray code: meaning and examples

Gray code is an ordering of binary numbers in which consecutive values differ in exactly one bit: 00, 01, 11, 10. Karnaugh maps label their rows and columns in this order so that neighbouring cells differ in one variable.

In ordinary binary counting, 01 is followed by 10, a change of two bits at once. Gray code, named after Frank Gray, reflects the sequence instead: 00, 01, 11, 10, and the sequence wraps, since 10 and 00 again differ in one bit. For four variables a map uses the two-bit Gray sequence on both axes, so each cell has four neighbours differing in one variable each, including across the edges. That is what makes the grouping rule work: adjacent cells can be merged because only one variable changes between them.

The artefact on this page is Σm(A, B, C, D; 0, 2, 8, 10), whose four true cells are the four corners of a four-variable map. In Gray-code order the corners are neighbours: cells 0 and 2 differ only in C, cells 0 and 8 only in A. The engine's map finds a single group of those four cells and derives NOT B AND NOT D, two literals for four minterms, 1 prime implicant, no don't-cares, equivalent on every assignment. The satisfiable witness A = FALSE, B = FALSE, C = FALSE, D = FALSE is cell 0.

Beyond maps, Gray code is used in rotary encoders and in error-tolerant counters, where a one-bit change per step avoids transient wrong readings. The term is confused with binary order, which is why a map drawn with columns 00, 01, 10, 11 produces wrong groups, and it is sometimes assumed to be a single sequence, whereas any ordering with the one-bit property is a Gray code.

Example

f := Σm(A, B, C, D; 0, 2, 8, 10) · output

Exact checks

Always true (tautology)? No Counterexample: A = F, B = F, C = F, D = T · Exhaustively checked and solver cross-checked · 2 rows
Always false (contradiction)? No Counterexample: A = F, B = F, C = F, D = F · Exhaustively checked and solver cross-checked · 1 rows
Can be true? Yes Example assignment: A = F, B = F, C = F, D = F · Exhaustively checked and solver cross-checked · 1 rows

Truth table (16 rows)

Gray code: meaning and examples
#ABCDf
0FALSEFALSEFALSEFALSETRUE
1FALSEFALSEFALSETRUEFALSE
2FALSEFALSETRUEFALSETRUE
3FALSEFALSETRUETRUEFALSE
4FALSETRUEFALSEFALSEFALSE
5FALSETRUEFALSETRUEFALSE
6FALSETRUETRUEFALSEFALSE
7FALSETRUETRUETRUEFALSE
8TRUEFALSEFALSEFALSETRUE
9TRUEFALSEFALSETRUEFALSE
10TRUEFALSETRUEFALSETRUE
11TRUEFALSETRUETRUEFALSE
12TRUETRUEFALSEFALSEFALSE
13TRUETRUEFALSETRUEFALSE
14TRUETRUETRUEFALSEFALSE
15TRUETRUETRUETRUEFALSE

Plain-language reading

Beginnerf is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10.
In every other case, f is false.
About the operators:
- Σm lists the truth-table rows (minterms) where the formula is true. Rows are numbered from 0 with the first listed input as the most significant bit.
Intermediatef is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10.
In every other case, f is false.
Advancedf is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10 [canonical sum of minterms (DNF)].
In every other case, f is false.
Formal notation: Σm(A, B, C, D; 0, 2, 8, 10)

Karnaugh map

AB \ CD
00
01
11
10
00
1m0
0m1
0m3
1m2
01
0m4
0m5
0m7
0m6
11
0m12
0m13
0m15
0m14
10
1m8
0m9
0m11
1m10
  1. cells m0, m2, m8, m10NOT B AND NOT D
NOT B AND NOT D · Derived NOT B AND NOT D. Exactly equivalent on every assignment.

The common slip

Labelling map columns in counting order, 00, 01, 10, 11. The middle two then differ in two bits, cells that look adjacent are not, and a group that spans them is not a single term. The Gray order 00, 01, 11, 10 is the whole point of the map.

Questions

Why are the corners of a map adjacent?

Because Gray code wraps: the first and last labels, 00 and 10, differ in one bit, so the leftmost and rightmost columns are neighbours, and so are the top and bottom rows. The four corners form a legal group of four, as this page shows.

Related

Guides

See also

Glossary

Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.