---
title: "Gray code and 3-bit binary-to-Gray converter"
subject: "Digital Logic"
chapter: 1
key: "semester_3/digital_logic:gray-code-binary-gray-converter"
source: https://www.bctengineer.com/q/semester_3/digital_logic/gray-code-binary-gray-converter
site: BCT Engineering
---

# Gray code and 3-bit binary-to-Gray converter

Digital Logic · Chapter 1: Introduction

- Asked in: 2080 Bhadra, 2+3+1 marks
- Video: [Binary Code to Gray Code Converter: Circuit, Truth Table, and Designing](https://www.youtube.com/watch?v=Pk9YouWUwHI) — Engineering Funda
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/digital_logic/gray-code-binary-gray-converter
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-1

## Question

Define Gray Code. Design 3-bit binary to gray code converter circuit with necessary truth table and circuit diagram.

## Short answer

Gray code: successive numbers differ by one bit. A 3-bit binary to Gray converter: truth table gives G2=B2, G1=B2⊕B1, G0=B1⊕B0. Circuit uses two XOR gates. Example: binary 010 yields Gray 011.

## Answer

#### Gray code
**Gray code** is an unweighted, reflected binary code in which **successive numbers differ in only one bit position**. Examples: 0 = 000, 1 = 001, 2 = 011, 3 = 010. It is used in shaft encoders and K-maps because only one bit changes at each step, avoiding false intermediate values.

#### 3-bit binary to Gray code converter
Inputs: $B_2B_1B_0$ (binary, $B_2$ = MSB). Outputs: $G_2G_1G_0$.

#### Truth table (3-bit binary to Gray)

| $B_2$ | $B_1$ | $B_0$ | $G_2$ | $G_1$ | $G_0$ |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 | 1 | 1 |
| 1 | 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |

#### Simplification (K-maps)
- $G_2 = \sum m(4,5,6,7) = B_2$
- $G_1 = \sum m(2,3,4,5) = \bar B_2 B_1 + B_2\bar B_1 = B_2 \oplus B_1$
- $G_0 = \sum m(1,2,5,6) = \bar B_1 B_0 + B_1\bar B_0 = B_1 \oplus B_0$

K-map for $G_1$ (rows $B_2$, columns $B_1B_0$):

```text
        B1B0
 B2    00  01  11  10
  0  |  0 | 0 | 1 | 1 |
  1  |  1 | 1 | 0 | 0 |
```

#### Logic circuit

```text
 B2 ---+------------------------ G2
       |    +-------+
       +--->|       |
            |  XOR  |----------- G1
 B1 ---+--->|       |
       |    +-------+
       |    +-------+
       +--->|       |
            |  XOR  |----------- G0
 B0 ------->|       |
            +-------+
```

The converter needs only **two XOR gates**: the MSB passes straight through and each other Gray bit is the XOR of two neighbouring binary bits.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the defining property of Gray code?
   A. Each bit has weights 8, 4, 2, 1
   B. Each decimal digit is coded as digit + 3
   C. Successive numbers differ in exactly one bit
   D. Successive numbers differ in exactly two bits
   Answer: C. Gray code is a unit-distance code: consecutive values differ in only one bit. (Key point: Gray code definition)

2. Which equations give the 3-bit binary to Gray converter?
   A. G2 = B2 XOR B1, G1 = B1 XOR B0, G0 = B0
   B. G2 = B2, G1 = B1, G0 = B0
   C. G2 = B2 AND B1, G1 = B1 AND B0, G0 = B0
   D. G2 = B2, G1 = B2 XOR B1, G0 = B1 XOR B0
   Answer: D. The MSB passes straight through and each other Gray bit is the XOR of neighbouring binary bits. (Key point: 3-bit converter equations)

3. Which expression does the K-map of G1 give?
   A. B2 XOR B1
   B. B2 AND B1
   C. B1 XOR B0
   D. B2 OR B1
   Answer: A. G1 = m(2,3,4,5) = B2'B1 + B2B1' = B2 XOR B1. (Key point: K-map of G1)

4. How many gates does the 3-bit binary to Gray converter need?
   A. Three XOR gates
   B. Two XOR gates
   C. Two AND gates and one OR gate
   D. Three NOT gates
   Answer: B. G2 is a direct wire; G1 and G0 each need one XOR gate. (Key point: Gates needed)

## Related in Digital Logic

- [BCD code and 3-bit binary-to-Gray converter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Abcd-code-gray-converter) — Digital Logic, chapter 1
- [3-bit Gray code synchronous counter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-code-sync-counter-3bit) — Digital Logic, chapter 8, asked 2×
- [ASCII code and binary-to-Excess-3 converter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aascii-binary-excess3-converter) — Digital Logic, chapter 1, asked 2×
- [Excess-3 code and binary-to-Excess-3 converter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Aexcess3-binary-converter) — Digital Logic, chapter 1, asked 2×
- [Sync vs async; 3-bit Gray code counter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-sync-counter-advantages) — Digital Logic, chapter 8
- [Gray vs binary code, convert (10110)₂ to Gray](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-vs-binary-convert-10110) — Digital Logic, chapter 1

## Related in other subjects

- [JK flip-flop operation and truth table](https://www.bctengineer.com/question.md?key=semester_2%2Fbasic_electronics_engineering%3Ajk-flip-flop) — Basic Electronics Engineering, chapter 6
- [Bit error probability for binary ASK](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Abinary-ask-ber) — Communication Systems, chapter 9
