Gray Code to Binary Converter – XOR Steps Explained in 3 Easy Steps
Gray Code to Binary Converter
Use this Gray code to binary converter to change binary to Gray code or vice versa. See the exact XOR (Exclusive OR) logic steps in real-time.
Use this free Gray code to binary converter to switch between standard binary and reflected binary (Gray) code in either direction. Type a binary number to get its Gray code, or type Gray code to get the binary value, and the logic visualizer shows every XOR step so you can follow or check the working.
Quick answer
To convert binary to Gray code, keep the most significant bit, then XOR each binary bit with the bit to its left: Gi = Bi−1 ⊕ Bi. To convert Gray code back to binary, keep the first bit, then XOR each Gray bit with the previous binary result: Bi = Bi−1 ⊕ Gi. For example, binary 101101 becomes Gray 111011, and Gray 1101 becomes binary 1001.
Table of Contents
Gray code is a staple of digital electronics, rotary encoders and error-resistant data transfer, and it is a common topic in computer science and engineering exams. Converting long numbers by hand is slow and easy to get wrong, one XOR at a time.
This gray code to binary converter does the work instantly and shows each bit so you can learn the method, not just copy the answer. It runs in your browser.
What Is Gray Code?
Gray code, also called reflected binary code, is a way of ordering binary numbers so that two neighbouring values differ by only one bit. Counting from 3 to 4 in normal binary changes three bits (011 to 100). In Gray code it changes just one (010 to 110). That property prevents glitches when several bits would otherwise switch at slightly different moments.
It is named after Frank Gray, a Bell Labs researcher who patented its use in 1953, although the idea is older.
Binary to Gray Code Conversion Steps
- Copy the most significant (leftmost) bit unchanged.
- For each next position, XOR the current binary bit with the binary bit to its left.
- Write the result as the Gray code bit for that position.
- Repeat until you reach the last bit.
Example: binary 101101 → 1, then 1⊕0 = 1, 0⊕1 = 1, 1⊕1 = 0, 1⊕0 = 1, 0⊕1 = 1, giving Gray code 111011. A quick shortcut for whole numbers is Gray = n XOR (n shifted right by one bit).
Gray Code to Binary Conversion Steps
- Copy the most significant Gray bit as the first binary bit.
- XOR the binary bit you just wrote with the next Gray bit.
- Write the result as the next binary bit.
- Continue to the end.
Example: Gray 1101 → 1, then 1⊕1 = 0, 0⊕0 = 0, 0⊕1 = 1, giving binary 1001.
4-Bit Binary and Gray Code Table
| Decimal | Binary | Gray code |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
| 8 | 1000 | 1100 |
| 9 | 1001 | 1101 |
| 10 | 1010 | 1111 |
| 11 | 1011 | 1110 |
| 12 | 1100 | 1010 |
| 13 | 1101 | 1011 |
| 14 | 1110 | 1001 |
| 15 | 1111 | 1000 |
How to Use the Gray Code to Binary Converter
Step 1: Enter a Binary Number
Type a binary value in the Standard Binary box. The Gray code appears instantly. Here 101101 converts to 111011. Use the copy buttons to grab either value.

Step 2: Follow the XOR Logic Steps
The Logic Operations Visualizer lists every bit: the MSB carried over, then each XOR between neighbouring binary bits and the Gray bit it produces. It is handy for homework and lab reports.

Step 3: Convert Gray Code Back to Binary
Type in the Gray Code box to reverse the process. Gray 1101 returns binary 1001, and the visualizer switches to Gray-to-binary mode. The 3-bit reference table at the bottom gives a quick check for small values.

Where Gray Code Is Used
- Rotary and linear encoders: position sensors use Gray code so a reading between two positions is never wildly wrong.
- Karnaugh maps: rows and columns are labelled in Gray order so adjacent cells differ by one variable.
- Digital communications: Gray-coded modulation reduces the number of bit errors when a symbol is misread.
- Asynchronous FIFOs: hardware designers pass Gray-coded counters between clock domains safely.
- Puzzles and games: the Tower of Hanoi and some combination puzzles follow Gray code patterns.
Working with other codes? Try the Excess-3 Code Converter for BCD-style encoding or the Base58 Encoder Decoder for crypto addresses.
Frequently Asked Questions
How do I convert binary to Gray code?
Keep the first bit, then XOR each bit with the bit before it. Binary 1010 becomes Gray 1111.
How do I convert Gray code to binary?
Keep the first bit, then XOR each Gray bit with the previous binary bit. Gray 1111 becomes binary 1010.
Why is Gray code used?
Because only one bit changes between consecutive values, which avoids errors in encoders, counters and digital signals.
Is Gray code the same as reflected binary code?
Yes. Reflected binary code is another name for the standard Gray code.
What is the Gray code for decimal 7?
Decimal 7 is 0111 in binary and 0100 in Gray code.
Is my input stored?
No. The gray code to binary converter runs entirely in your browser.