Gray Code Converter

Convert between Binary and Gray Code with step-by-step conversion process. Essential for digital systems, encoders, and error-resistant data transmission.

✓ Binary → Gray Code ✓ Gray Code → Binary ✓ Step-by-step process

Gray Code Conversion

What is Gray Code?

Gray Code, also known as reflected binary code or unit distance code, is a binary numeral system where two successive values differ in only one bit. This property makes it valuable for applications where errors in bit transitions need to be minimized.

Gray Code Properties

Single Bit Change

The key feature of Gray Code is that consecutive numbers differ by exactly one bit. This eliminates the possibility of multiple bit errors during transitions.

Cyclic Nature

Gray Code is cyclic, meaning the last code word differs from the first by only one bit, making it suitable for rotary encoders and circular applications.

Conversion Rules

Binary to Gray Code

  1. MSB: G₀ = B₀ (Most significant bit remains the same)
  2. Other bits: Gᵢ = Bᵢ₋₁ ⊕ Bᵢ (XOR previous with current)

Gray Code to Binary

  1. MSB: B₀ = G₀ (Most significant bit remains the same)
  2. Other bits: Bᵢ = Bᵢ₋₁ ⊕ Gᵢ (XOR previous result with current Gray)

Comparison Table

DecimalBinaryGray CodeBit Changes
0000000-
10010011 bit
20100111 bit
30110101 bit
41001101 bit
51011111 bit
61101011 bit
71111001 bit

Applications

Rotary Encoders

  • Position sensing
  • Motor control
  • Robotics applications
  • Industrial automation

Digital Communication

  • Error-resistant data transmission
  • Analog-to-digital converters
  • Phase-shift keying
  • Satellite communication

Karnaugh Maps

  • Variable ordering
  • Logic minimization
  • Boolean algebra simplification

Advantages

Error Reduction

Single bit transitions reduce the likelihood of errors during mechanical or electrical switching, making systems more reliable.

Glitch Prevention

In digital systems, Gray Code prevents glitches that can occur when multiple bits change simultaneously in binary counting.

Examples & Practice

Example 1: Binary 1011 to Gray

  • G₀ = B₀ = 1
  • G₁ = B₀ ⊕ B₁ = 1 ⊕ 0 = 1
  • G₂ = B₁ ⊕ B₂ = 0 ⊕ 1 = 1
  • G₃ = B₂ ⊕ B₃ = 1 ⊕ 1 = 0
  • Result: 1110

Example 2: Gray 1110 to Binary

  • B₀ = G₀ = 1
  • B₁ = B₀ ⊕ G₁ = 1 ⊕ 1 = 0
  • B₂ = B₁ ⊕ G₂ = 0 ⊕ 1 = 1
  • B₃ = B₂ ⊕ G₃ = 1 ⊕ 0 = 1
  • Result: 1011

Related Tools