Binary-coded decimal

BCD or BCD code (of English. Binary Coded Decimal) referred to in the computer science usually the 8-4 -2-1 Code. In this case, Binary Coded Decimal can be translated as binary coded decimal. There then is a numeric code that dual encoding each digit of a decimal number individually. The sequence of digits 8-4-2-1 stands for the values ​​of the digits in a dual -coded decimal digit. In some cases, with the general BCD binary coding of individual decimal digits indicated (see below). The BCD code should not be confused with the BCD count code.

Coding

To represent a number as a BCD number, any decimal digit (0 to 9) represented by four bits ( 0000-1001, see code table), so in a nibble (nibble ). The remaining six values ​​( 10102-11112 ), which can be represented with four bits, are not a valid BCD numbers and are also referred to as pseudo tetrades.

To encode numbers with more than one decimal digit BCD representations of individual digits are consecutively set (eg, the number is 2687 0010 0110 1000 0111 as shown). With a byte (8-bit ), two decimal digits can be displayed. If the 4 bits of a BCD number encoded in each of the low-order bits and made up the remaining 4 bits with zeros, then one speaks of an unpacked BCD number. If both halves of a byte each filled with a BCD number, it is called according to a packed BCD number.

The number 10 is the smallest number, the binary code ( 0000 1010), and BCD (0001 0000) is coded differently. As in hexadecimal representation corresponding to four bits of a digit, BCD-coded numbers in hexadecimal notation are directly visually readable. This also applies to multi-digit numbers.

The representation of signed numbers requires another separate bit when the encoded range for negative and positive values ​​should be equal. With 16 bits are thus only 3 digits coded ( -999 to 999 ) because stand for the 4th position no 4 bits longer available. Encodings by pseudo tetrades are only possible if the display area is asymmetric (eg -09.99 ° C to 99.99 ° C) or if the most significant digit can take a maximum value of 7 (eg, -199, 9 ° to 199.9 ° C).

Application

BCD arithmetic is nowadays rarely used because it uses the memory wasteful and compared with the 32 -bit floating-point provides a few advantages with respect to accuracy. However, large banks still need an accuracy, which goes beyond the floating point representation. Therefore mainframe Densely Packed Decimal Encoding using the.

BCD arithmetic is a relic of times when you wanted to keep the cost of the conversion between internal representation and external representation small. The lack of representation of decimal rounding errors can be achieved by floating-point numbers with base -10 exponent or by fixed-point numbers with base -10 exponent as well. The processing speed of the display is higher than that of BCD representation for current processors 2 to 2 1/2 orders of magnitude. The number is not in a form M * 2E, but in the form M * 10E saved. M is the (integer ) mantissa and e is the exponent. Both are stored in binary, for commercial solutions is e anyway usually fixed at -2 (most bills ) or -4 ( phone bills ).

In calculating units of the BCD code is little used because circuits that expect BCD numbers, significantly more switching elements ( gates) need as circuits that work with binary numbers. The Code does, however, occasionally in control systems, for example for control of LCD or LED number displays, as well as the sending of SMS messages in the so called PDU format, application.

Today's processors have either no support from BCD arithmetic more or it is stopped at the level of 8 -bit processors ( that is, there are 8- bit addition and subtraction of 8-bit supported). But there were processors with extensive support of BCD arithmetic ( eg the Sharp SC61860 in the Sharp PC -1401 ). Today's processors have Intel in 64- bit mode, not a single command to BCD arithmetic more. There are two commands for quick conversion of 80 -bit BCD to 80 -bit double extended. The actual calculations are always performed in the binary system.

Furthermore, the BCD code is used to encode the time in the DCF77 signal. Digital clocks run inside in BCD code. Compared to binary counters no further gates are necessary. The conversion of the meter reading by LCD is significantly easier. Some AD converter provide her measurement result directly from a BCD number.

Other BCD codes

It should be noted that the BCD - code is used in other formats. For example, even the 1-of- 10 code, the 2 of 5 code, 5 -4-2 -1 code and the 2- 4-2- 1 code (also Aiken code) Excess 3 code and gray code in use. These differ, as can be seen in part in the description, in the vacancy significance of the individual bits. The 1-of- 10 code and the 2-of- 5 code are primarily used for error analysis. By using the Chen -Ho encoding or Densely -Packed -Decimal - coding can be 3 decimal digits by 10 bits instead of 12 bits encode. This provides a 20% better efficiency, because there are only 24 possible pseudo tetrades 1024.

792
de