Web4College
Binary to Gray code · Step by step
Space plays or pauses. Arrow keys step. Ctrl plus arrows changes chapter. Shift plus greater or less changes speed. Escape releases focus.
Read from left to right. Copy the first bit, then XOR each pair of adjacent bits from the original binary input.Original binaryLeft → rightBit 11Bit 20Bit 31Bit 41One Gray bit at a timeGray code

Binary to Gray Code Converter

1110

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

  1. Keep the first bit unchanged. The first Gray code bit is the same as the first binary bit.
  2. Compare neighboring bits. Take each pair of neighboring bits from the original binary number.
  3. Apply XOR. Write 0 if the two bits are the same, or 1 if they are different.
  4. 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

BinaryGray code
00000000
00110010
01110100
10001100
11111000
1010101011111111

Key terms

TermMeaning
BitA single binary digit: 0 or 1.
Gray codeA code where consecutive values differ by one bit.
XORExclusive OR: same bits → 0; different bits → 1.