lulupedia
srpskohrvatski / српскохрватски 版本暂未收录,当前展示 English 内容。

BCD

5239 words·24. 9. 2026.·English
0

Binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, usually four, serving as a fundamental method for representing and processing decimal data in digital systems. While the acronym BCD can refer to various concepts such as Boot Configuration Data in computing or Buoyancy Control Device in scuba diving, it is most prominently and universally recognized in computer science and digital electronics as Binary-Coded Decimal.

Principles and Encoding

In the most common BCD encoding scheme, known as 8421 BCD or simply BCD, each of the ten decimal digits (0 through 9) is represented by its corresponding four-bit binary value. The weights of the four bits from most significant to least significant are 8, 4, 2, and 1, respectively. For example, the decimal digit 5 is encoded as 0101 (4+1), and 9 is encoded as 1001 (8+1). The six remaining four-bit combinations (1010 through 1111) are considered invalid or "pseudo-tetrades" in standard BCD, though they may be used for special purposes such as representing signs or decimal points in specific implementations.

When representing multi-digit decimal numbers, each digit is encoded independently. For instance, the decimal number 459 is encoded in BCD as 0100 0101 1001. This contrasts with pure binary encoding, where the entire number is converted into a single binary value (459 in pure binary is 111001011).

Variations of BCD

Several variations of BCD have been developed to optimize storage, processing, or specific computational needs:

  • Unpacked BCD: Each decimal digit is stored in a separate byte (8 bits), with the upper four bits typically set to zero or used for zone indicators (as in EBCDIC zoned decimal formats). This format is straightforward but storage-inefficient.
  • Packed BCD: Two decimal digits are packed into a single byte, with one digit in the upper nibble (four bits) and the other in the lower nibble. For odd numbers of digits, the most significant nibble of the first byte is usually padded with zeros. A sign indicator is often placed in the lower nibble of the final byte (e.g., 1100 for positive, 1101 for negative).
  • Excess-3 (XS-3): A self-complementing BCD code where each digit is represented by its standard 8421 BCD value plus 3 (0011 in binary). This property simplifies subtraction operations, as the 9's complement of a digit can be obtained by simply inverting its bits.
  • Gray Code BCD: Uses Gray code to represent decimal digits, ensuring that only one bit changes between consecutive numbers, which minimizes errors in electromechanical switches and analog-to-digital converters.

Arithmetic Operations

Performing arithmetic in BCD requires specific adjustments because the underlying hardware operates in base-2, while BCD operates in base-10. When two BCD digits are added using standard binary addition, the result may exceed 9 or generate a carry that does not align with decimal rules.

To correct this, a "decimal adjust" operation is applied. If the sum of two BCD digits is greater than 9, or if a binary carry is generated from the lower nibble, the value 6 (0110 in binary) is added to the result. This adjustment skips the six invalid states (1010 to 1111) and correctly propagates the carry to the next decimal digit. Historically, microprocessors included a dedicated Decimal Adjust Accumulator (DAA) instruction to automate this correction after binary addition. Subtraction is similarly handled, often utilizing 10's complement arithmetic and adjusting by subtracting 6 when a borrow occurs.

Advantages and Disadvantages

The primary advantage of BCD is its exact representation of decimal fractions. In pure binary, many common decimal fractions (such as 0.1 or 0.2) result in infinitely repeating binary fractions, leading to rounding errors. BCD avoids this entirely, making it indispensable in financial, accounting, and commercial applications where exact decimal precision is legally and practically required. Additionally, converting between BCD and human-readable character formats (like ASCII or EBCDIC) is computationally trivial, requiring only the addition or removal of a constant offset.

Conversely, BCD has notable disadvantages. It is less storage-efficient than pure binary, as it utilizes only 10 out of the 16 possible states in a four-bit nibble, resulting in a roughly 20% waste of storage capacity. Furthermore, arithmetic operations are generally slower and require more complex circuitry or additional instructions compared to pure binary arithmetic, as the decimal adjustment steps add processing overhead.

Applications

Due to its precision and ease of conversion, BCD has been widely used in various domains. In early computing, systems like the IBM System/360 heavily utilized packed BCD for commercial data processing. Today, BCD remains the standard for financial systems, database management systems (such as the DECIMAL or NUMERIC data types in SQL), and programming languages that require arbitrary-precision decimal arithmetic (like Python's decimal module or Java's BigDecimal). It is also prevalent in digital clocks, electronic calculators, and digital multimeters, where the direct mapping to seven-segment displays simplifies hardware design. Furthermore, BCD encoding is used in telecommunications, such as in the representation of phone numbers in GSM networks.

Other Meanings

While Binary-Coded Decimal is the most prominent technical definition, the acronym BCD is also used in several other contexts:

  • Boot Configuration Data: A firmware-independent database used by the Windows Boot Manager in Microsoft Windows operating systems to configure boot-time applications.
  • Buoyancy Control Device: A critical piece of scuba diving equipment used by divers to maintain neutral buoyancy underwater.
  • BCD Travel: A global travel management company providing corporate travel services.
  • Bipolar-CMOS-DMOS (BCD process): A semiconductor manufacturing technology that integrates Bipolar, CMOS, and DMOS devices on a single chip, widely used in power management integrated circuits.

Comments (0)

U

No comments yet. Be the first to comment!

You May Be Interested In

Related Articles