User Tools

Site Tools


tanszek:oktatas:techcomm:bcd_encoding

BCD (Binary-Coded Decimal) Encoding

Binary-Coded Decimal (BCD) is a class of binary encodings in which each decimal digit is represented by its own binary sequence. In BCD, the binary form of a decimal number is encoded such that a 4-bit binary number represents each digit.

Each decimal digit (0-9) is represented using 4 bits, as follows:

0000 represents 0
0001 represents 1
0010 represents 2
0011 represents 3
0100 represents 4
0101 represents 5
0110 represents 6
0111 represents 7
1000 represents 8
1001 represents 9

Each decimal digit is encoded separately. For example, the decimal number 59 in BCD would be:

0101 1001

Key Features of BCD

  • Easy Conversion: BCD is easy to convert between binary and decimal since each digit is encoded individually.
  • Limited Range: BCD only supports decimal digits from 0 to 9 (0000 to 1001 in binary), leaving six unused binary combinations in a 4-bit group (1010 to 1111 are invalid).
  • Space Inefficiency: BCD encoding is less space-efficient than regular binary representation because it uses more bits to represent numbers. For example, to represent 255 in regular binary, 8 bits are sufficient (11111111), but in BCD, it requires 12 bits (0010 0101 0101).

Applications of BCD

BCD encoding is often used in applications where human-readable decimal output is crucial and precision matters. Common use cases include:

  • Digital clocks (old ones): These devices often display numbers directly in decimal form, so BCD simplifies the process.
  • Financial applications: BCD can be used in systems requiring precise decimal representation, such as in currency and banking systems, to prevent rounding errors.

How much is the redundancy of this encoding?

Equation of redundancy is as follows: \( R = \frac{H_{\text{max}} - H}{H_{\text{max}}} \)

where:

  • \(H_{\text{max}}\) is the maximum entropy,
  • \(H\) is the actual entropy.

Each decimal digit (0–9) is represented by a 4-bit binary code. However, 4 bits can represent 16 possible combinations (0000–1111), of which only 10 are used.

Maximum entropy:

$$ H_{\text{max}} = \log_2(16) = 4\ \text{bits per symbol} $$

Actual entropy:

Since only 10 symbols are used and they are equally likely:

$$ H = \log_2(10) \approx 3.3219\ \text{bits per symbol} $$

Substitute these values into the equation of redundancy:

$$ R = \frac{4 - 3.3219}{4} = 0.1695 $$

Thus, the redundancy of the BCD code is approximately 16.95%.

This means that about 17% of the information capacity of the 4-bit representation is not used effectively due to the limited number of valid BCD codes.

tanszek/oktatas/techcomm/bcd_encoding.txt · Last modified: 2025/10/27 18:53 by knehez