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

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

Digital Logic · Chapter 1: Introduction

- Asked in: 2081 Bhadra, 2+4 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/bcd-code-gray-converter
- Whole chapter: https://www.bctengineer.com/md/semester_3/digital_logic/chapter-1

## Question

What is a BCD code? Design a 3-bit binary to Gray code converter.

## Short answer

BCD encodes each decimal digit in 4-bit binary (8421), valid 0000–1001. A 3-bit binary to Gray converter: G2 = B2, G1 = B2⊕B1, G0 = B1⊕B0, implemented with two XOR gates. Example: binary 101 yields Gray 111.

## Answer

#### BCD code
**BCD (Binary Coded Decimal)** represents each decimal digit separately by its 4-bit binary value (8421 weights). Only 0000–1001 are valid; 1010–1111 are invalid.
Example: $(93)_{10}$ = 1001 0011 (BCD), while in binary $93 = 1011101_2$. BCD is used in calculators, clocks and 7-segment displays.

#### 3-bit binary to Gray code converter
Inputs: binary $B_2B_1B_0$ ($B_2$ = MSB). Outputs: Gray $G_2G_1G_0$. In Gray code, successive values differ in only one bit.

#### 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 BCD?
   A. The whole decimal number is converted to binary
   B. Each digit is coded as digit + 3
   C. Each decimal digit is coded separately by its 4-bit binary value
   D. A code where successive values differ by one bit
   Answer: C. BCD uses 8421 weights, valid codes 0000-1001. (Key point: BCD 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. For binary 100 (B2B1B0), what is the Gray output?
   A. 110
   B. 100
   C. 010
   D. 101
   Answer: A. G2=1, G1=1^0=1, G0=0^0=0. (Key point: Truth table)

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

- [Gray code and 3-bit binary-to-Gray converter](https://www.bctengineer.com/question.md?key=semester_3%2Fdigital_logic%3Agray-code-binary-gray-converter) — Digital Logic, chapter 1
- [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×
- [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×
- [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

- [8085 ALP: BCD to binary conversion](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-bcd-to-binary) — Microprocessor, chapter 2
