Binary↔ Gray Code
Conversion
Introduction
Binary uses only 0 and 1. Gray code (reflected binary) is a binary-derived
code where adjacent values differ by a single bit — minimizing switching
errors. This project demonstrates conversion both ways and validates
designs on a breadboard with IC 7486 (XOR).
Objectives
Explain Binary and Gray code fundamentals.
Design Binary→Gray and Gray→Binary converters.
Implement converters using XOR gates (IC 7486).
Test on breadboard and verify with truth tables and LEDs.
What is Binary?
Binary is a base-2 numeral system using digits 0 and 1. It is the fundamental
language for digital circuits and computers. Example conversions: Decimal 5
→ 0101 (4-bit), Decimal 10 → 1010 (4-bit).
What is Gray Code?
Gray code (Reflected Binary Code) ensures adjacent codes differ by only
one bit, which reduces transient switching errors in encoders and digital
interfaces. Common uses: rotary encoders, position sensors, certain
communication links, and Karnaugh map ordering.
Binary → Gray Conversion
Rule: MSB stays the same. Remaining Gray bits are XORs of
adjacent Binary bits.
Formulas (4-bit) — G3 = B3; G2 = B3 ⊕ B2; G1 = B2 ⊕ B1;
G0 = B1 ⊕ B0.
Implement by wiring XOR gates so each Gray output (except
MSB) is the XOR of the specified Binary inputs.
Gray → Binary Conversion
Rule: MSB remains same. Recover lower-order Binary bits
iteratively using XOR with previously recovered Binary bits.
Formulas (4-bit) — B3 = G3; B2 = B3 ⊕ G2; B1 = B2 ⊕ G1;
B0 = B1 ⊕ G0.
Practical note: Implement with XOR gates cascaded so each
stage uses the earlier computed Binary bit.
XOR GATE
TRUTH TABLE XOR GATE DIAGRAM
Logic Symbol
XOR Output
A B
(AB) A
XOR Y=A В
0 이 이 B
이 1 1
Boolean Expression
1 이 1 Y= AВ
1 1 이
Logic Circuit (Using Basic Gates)
A
EXPLANATION
XOR output is 1 when inputs are different.
XOR output is 0 when inputs are same. Y=AB
B
Made with GAMMA
Practical Implementation —
Components & Procedure
Components Step-by-step
IC 7486 (XOR), breadboard, 1. Place IC and power rails on
LEDs, resistors, switches, breadboard and supply
jumper wires, 5V power supply. Vcc/GND.
2. Wire Binary inputs via
switches; connect XOR
gates per formulas.
3. Add LEDs with resistors to
outputs for visual
verification.
4. Test all 16 input
combinations, record
outputs, compare with truth
table.
Tips
Use short jumpers, a common ground, and debounce switches if
needed. Label inputs/outputs on the breadboard for clarity.
Results, Applications &
Conclusion
Results: Both converters functioned as expected;
outputs matched theoretical truth tables across all input
combinations. Practical learning: cascading XOR logic,
timing considerations, and breadboard assembly skills.
Final note: Gray coding remains a practical technique
for minimizing spurious transitions in real-world digital
systems. For lab instructors — encourage students to
test timing and race conditions when cascading gates.
Applications Advantages
Rotary encoders, digital counters, error-reducing interfaces, Single-bit transitions reduce glitches; simple XOR
Karnaugh map sequencing. implementation; robust for many embedded systems.