Gray Code Table Generator
List all 2^N Gray codes for N bits (1 to 8). Shows binary side-by-side and highlights the 1-bit transition.
| i | Binary | Gray |
|---|
Gray code: counting one bit at a time
In ordinary binary counting, going from 7 to 8 changes four bits at once: 0111 becomes 1000. In a real circuit those bits do not switch at the same instant, and during the transition the reading can be anything — including a number matching neither value. Gray code removes the problem at the root: between two consecutive values, exactly one bit changes.
Choose the number of bits, from 1 to 8, and the page builds the full table with the decimal, ordinary binary and matching Gray value. The conversion is surprisingly simple: take the exclusive-or of the number with itself shifted one bit right. The way back is less direct, because each bit of the result depends on all the more significant bits already decoded.
Where this genuinely matters is in a rotary encoder, the disc reporting a shaft's position. With ordinary binary, reading at the wrong instant returns an absurd position; with Gray, the worst case is reading a neighbour. The same idea appears in Karnaugh maps, where Gray ordering makes adjacent cells differ in a single variable, and in analogue-to-digital converters.
Frequently asked questions
Is there only one Gray code?
Does the sequence close the loop?
How do I convert from Gray back to binary?
Related Tools
JavaScript Formatter
Format and indent JavaScript code for better readability and debugging.
Markdown Table Generator
Build Markdown tables visually — add rows and columns, edit cells and copy the GFM syntax ready for README, Notion or GitHub. No manual formatting.
JSON ↔ CSV Converter
Convert data between JSON (array of objects) and CSV bidirectionally. Paste and convert instantly in the browser, no file upload needed.
Truth Table
Generate truth tables for Boolean logic expressions. Supports AND, OR, NOT, XOR, NAND and NOR. Auto-detects variables and shows all possible combinations. Processed in the browser.
HTML Formatter
Format and indent HTML code for better readability. Ideal for reviewing and debugging HTML quickly.
Hamming Code (7,4) Generator
Encode 4 data bits into 7 Hamming bits with parity, capable of correcting 1 wrong bit. Also demonstrates error detection.