--:--:--

Gray Code Visualizer

Gray code is a binary numeral system where two successive values differ in only one bit.

Formula: gray(i) = i ^ (i >> 1)

The red highlighted bits show which bit changed from the previous step. The marker indicates the position of the changed bit.

Step 1 / 8
iBinaryi >> 1Gray CodeDecChanged Bit
00000000000
10010000011··
20100010113··
30110010102··
41000101106··
51010101117··
61100111015··
71110111004··

Calculation for step 0

0 ^ (0 >> 1) = 0 ^ 0 = 0

Binary: 000 (0 in decimal)

Right shift (i >> 1): 000 (0 in decimal)

XOR result: 000 (0 in decimal)

Properties of Gray Code

  • Only one bit changes between consecutive values (Hamming distance = 1)
  • The sequence is cyclic (last value differs by 1 bit from first)
  • Used in error correction, digital communications, and rotary encoders