All Tools490+

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.

Standard Binary BIN
Gray Code GRAY
Logic Operations Visualizer
    3-Bit Reference Table
    Dec: 0B: 000 | G: 000
    Dec: 1B: 001 | G: 001
    Dec: 2B: 010 | G: 011
    Dec: 3B: 011 | G: 010
    Dec: 4B: 100 | G: 110
    Dec: 5B: 101 | G: 111
    Dec: 6B: 110 | G: 101
    Dec: 7B: 111 | G: 100
    Gray Code is a reflected binary code where two successive values differ by only one bit, preventing spurious outputs in digital switches.
    Copied to clipboard! ✓

    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.

    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

    1. Copy the most significant (leftmost) bit unchanged.
    2. For each next position, XOR the current binary bit with the binary bit to its left.
    3. Write the result as the Gray code bit for that position.
    4. 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

    1. Copy the most significant Gray bit as the first binary bit.
    2. XOR the binary bit you just wrote with the next Gray bit.
    3. Write the result as the next binary bit.
    4. 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

    DecimalBinaryGray code
    000000000
    100010001
    200100011
    300110010
    401000110
    501010111
    601100101
    701110100
    810001100
    910011101
    1010101111
    1110111110
    1211001010
    1311011011
    1411101001
    1511111000

    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 1 enter binary 101101 in the gray code to binary converter

    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 2 Gray code converter XOR logic steps

    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.

    Step 3 Gray code 1101 converted back to binary 1001

    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.

    MH

    Written and tested by Muhammad Hasnain

    Founder of VectraTools. The examples and the 4-bit table were checked against the tool and an XOR calculation. Last reviewed: October 2026.