// Gray Code - Binary numeral system with single-bit transitions
Only one bit changes between consecutive values.
Reduces errors in analog-to-digital conversion.
First and last values differ by only one bit.
Gray code (reflected binary code) is a binary numeral system where two successive values differ in only one bit. Created by Frank Gray, it's formed by XORing each bit with the previous bit. This property makes it ideal for position encoders and error reduction in digital systems.
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 Note: Only 1 bit changes between consecutive Gray codes
Gray code, also known as reflected binary code, is a binary numeral system where two successive values differ in only one bit. It was invented by Frank Gray and is widely used in digital systems to prevent spurious output during transitions.
To convert binary to Gray: 1) Keep the MSB (most significant bit) as is, 2) XOR each bit with the previous bit. Formula: G[i] = B[i] XOR B[i-1]. For example, binary 1011 becomes Gray 1110.
Gray code prevents ambiguous readings during transitions. In binary, changing from 7 (0111) to 8 (1000) requires changing all 4 bits simultaneously. If not perfectly synchronized, intermediate values could be read. Gray code ensures only one bit changes at a time.
Gray code is used in rotary encoders, Karnaugh map simplification, error correction in digital communications, genetic algorithms, and analog-to-digital converters. It's essential wherever single-bit transitions are needed.