Binary to Gray code · Step-by-step visualization
Space plays or pauses. Arrow keys seek 3 seconds. Ctrl plus arrows changes chapter. Shift plus greater or less changes speed. Escape releases focus.Binary to Gray Code Converter with Step-by-Step Visualization
Change the binary input for an instant result, then play the conversion step by step.
Examples
Input
Output
Convert binary to Gray code instantly. Enter a binary number, copy the result, or watch the visualization to understand how each Gray bit is formed.
Purpose of Gray Code
Gray code changes only one bit between consecutive values, reducing reading errors in position sensors and rotary encoders.
For example, from decimal 7 to 8, binary changes from 0111 to 1000: all four bits change. Gray code changes from 0100 to 1100, so only one bit changes.
How to Convert Binary to Gray Code
- Keep the first bit unchanged. The first Gray code bit is the same as the first binary bit.
- Compare neighboring bits. Take each pair of neighboring bits from the original binary number.
- Apply XOR. Write 0 if the two bits are the same, or 1 if they are different.
- Repeat for every pair. Continue until you have calculated all the remaining Gray code bits.
Example: 1011 → 1110
Always compare bits from the original binary number, not the Gray code bits already calculated.
Spaces are ignored; leading zeros are preserved.
Binary to Gray Code Conversion Table
| Binary | Gray code |
|---|---|
0000 | 0000 |
0011 | 0010 |
0111 | 0100 |
1000 | 1100 |
1111 | 1000 |
10101010 | 11111111 |
Key terms
| Term | Meaning |
|---|---|
| Bit | A single binary digit: 0 or 1. |
| Gray code | A code where consecutive values differ by one bit. |
| XOR | Exclusive OR: same bits → 0; different bits → 1. |