Binary to BCD & BCD to Binary Conversion

Introduction

Binary Coded Decimal (BCD) is a binary-encoded representation of decimal numbers where each decimal digit is represented by its own fixed-length binary sequence. The most common BCD format is the 8421 BCD, in which each decimal digit 0-9 is encoded as a four-bit binary number from 0000 to 1001. Codes from 1010 to 1111 are unused (invalid) in standard BCD.

BCD is widely used in digital systems that interface with humans or decimal displays, for example digital clocks, calculators, meters and numeric displays, because it preserves decimal digit boundaries and simplifies decimal arithmetic and display driving.

Basic idea of conversion

  • To convert a binary number to BCD, one common method is to convert the binary number to its decimal equivalent, then encode each decimal digit separately into a four-bit BCD group.
  • To convert BCD to binary, one common method is to decode each four-bit BCD group to its decimal digit and then combine the decimal digits to form the full decimal number; finally convert that decimal number to binary if required.

Binary → BCD conversion

There are two standard approaches to convert a binary integer into BCD:

  • Conversion through decimal: convert binary → decimal → BCD (encode each decimal digit into 4 bits).
  • Direct binary-to-BCD algorithms (no intermediate decimal shown explicitly), the most common being the shift-and-add-3 method, also known as the Double Dabble algorithm. This is suitable for hardware implementation.

Method A - Via decimal (conceptual, simple)

Procedure:

  • Convert the binary number to its decimal value.
  • Separate the decimal number into its decimal digits.
  • Encode each decimal digit as a 4-bit BCD nibble (0000 for 0, 0001 for 1, ..., 1001 for 9).

Method B - Shift-and-add-3 (Double Dabble)

Overview:

  • Start with the binary number in a register, and a parallel set of BCD nibbles initialised to zero.
  • For each binary bit (from MSB to LSB): shift the entire set of BCD nibbles left by one bit and bring in the next binary bit into the least significant position; after each shift, for any BCD nibble whose value is 5 or more, add 3 (binary 0011) to that nibble. Repeat until all binary bits have been processed.
  • The BCD nibbles then contain the decimal digits of the value.

This algorithm maps naturally to combinational/sequential hardware and avoids an explicit decimal-conversion step.

Worked example - Binary to BCD

Example 1: (11110)2

First convert the binary to decimal.

Binary number: (11110)2

Compute the decimal equivalent:

1 × 2⁴

+ 1 × 2³

+ 1 × 2²

+ 1 × 2¹

+ 0 × 2⁰

= 16

+ 8

+ 4

+ 2

= 30

Worked example - Binary to BCD

Now convert the decimal number 30 into BCD by encoding each decimal digit.

Decimal digits: 3 and 0

3 in 4-bit BCD = 0011

0 in 4-bit BCD = 0000

Concatenate the nibbles: 0011 0000

Worked example - Binary to BCD

Result:

(11110)2 = (00110000)BCD

Notes on combinational implementation

When implementing binary→BCD conversion in combinational logic, one can derive Boolean expressions for each BCD output bit as functions of the binary input bits. A truth table that lists the BCD outputs for each binary input value (up to the required range) is used to derive Sum-of-Products (SOP) expressions which can be simplified by Karnaugh maps (K-maps).

Notes on combinational implementation

From such a table one may write SOP expressions for the BCD bits. These expressions are then simplified using K-maps to obtain minimal logic. The following placeholders indicate where such SOP expressions and K-maps would appear.

Notes on combinational implementation
Notes on combinational implementation
Notes on combinational implementation
Notes on combinational implementation
Notes on combinational implementation
Notes on combinational implementation

BCD → Binary conversion

Conversion from BCD to binary is the reverse process. Typical approaches are:

  • Decode each 4-bit BCD nibble to its decimal digit, combine the decimal digits to form the full decimal number, then convert that decimal number to binary.
  • Use arithmetic: multiply the higher-order decimal digits by 10 and add lower-order digits (for multi-digit BCD), then convert the resulting decimal to binary.
  • Implement direct combinational logic that maps each group of BCD bits to weighted binary outputs (useful in hardware where BCD digits are limited).

Worked example - BCD to Binary

Example 1: (00101000)BCD

Convert BCD to decimal by making four-bit groups.

Group the 8 bits into two nibbles:

High nibble = 0010

Low nibble = 1000

Worked example - BCD to Binary

Decode each nibble to decimal:

0010 (BCD) = 2

1000 (BCD) = 8

Combined decimal number = 28

Convert the decimal 28 to binary.

Divide 28 by 2 and record remainders (long division method):

28 ÷ 2 = 14 remainder 0

14 ÷ 2 = 7 remainder 0

7 ÷ 2 = 3 remainder 1

3 ÷ 2 = 1 remainder 1

1 ÷ 2 = 0 remainder 1

Worked example - BCD to Binary

Arrange the remainders from last to first to form the binary number.

Binary = 11100

Result:

(00101000)BCD = (11100)2

Remarks on invalid BCD codes and detection

Standard 4-bit BCD encodings only permit 0000 to 1001. Codes 1010-1111 are invalid and may indicate an error or overflow. Detection logic can be implemented that flags any nibble with bit pattern greater than 1001. A common detection method is to test if (B3 & (B2 | B1)) | (B3 & B2 & B1) - simpler Boolean forms can be derived and implemented.

Applications and circuit considerations

  • BCD is extensively used for human-friendly numeric displays (seven-segment drivers accept BCD-to-segment decoders).
  • Arithmetic with BCD requires special correction steps (for example, adding 6 when a BCD digit exceeds 9 after addition) - this is the basis of BCD adder correction logic.
  • For hardware converters, choose the method that matches constraints: Double Dabble or shift-add-3 for serial or iterative hardware; table-based or combinational logic for small bit widths; decimal-intermediate method for clarity in software.

Summary

BCD encodes each decimal digit into a 4-bit group (most commonly 8421 BCD). Converting binary ↔ BCD may be done by using an intermediate decimal representation or by direct algorithms suitable for hardware (shift-and-add-3). The examples above demonstrate both directions: (11110)2 → 30 → 0011 0000 (BCD), and (00101000)BCD → 2 8 → 28 → 111002. For practical digital designs, attention must be paid to invalid BCD patterns and to correction logic required when performing decimal arithmetic in BCD.

The document Binary to BCD & BCD to Binary Conversion is a part of the Electronics and Communication Engineering (ECE) Course Digital Circuits.
All you need of Electronics and Communication Engineering (ECE) at this link: Electronics and Communication Engineering (ECE)
Explore Courses for Electronics and Communication Engineering (ECE) exam
Get EduRev Notes directly in your Google search
Related Searches
Objective type Questions, Exam, Previous Year Questions with Solutions, practice quizzes, Extra Questions, study material, Free, Summary, pdf , past year papers, Viva Questions, Binary to BCD & BCD to Binary Conversion, shortcuts and tricks, Binary to BCD & BCD to Binary Conversion, mock tests for examination, video lectures, Important questions, MCQs, Binary to BCD & BCD to Binary Conversion, Sample Paper, ppt, Semester Notes;