| Binary-coded Decimal |
Website Links For Decimal |
Information AboutBinary-coded Decimal |
| CATEGORIES ABOUT BINARY-CODED DECIMAL | |
| computer arithmetic | |
| numeration | |
| SHOPPER'S DELIGHT | |
|
In BCD, a Digit is usually represented by four ( Binary ) Bit s, of which the leftmost (most significant bit written conventionally) has value 8, and the remaining three have values 4, 2, and 1. Many other ways of encoding ten values in four bits have been used, but in general only the combinations of bits which have values in the range 0-9 are valid. (Other combinations are sometimes used for Sign or other indications.) BASICS To BCD-encode a decimal number using the common encoding, each digit is encoded using the four-bit binary bit pattern for each digit. For example, the number 127 would be: 0001 0010 0111 Since most computers store data in eight-bit Byte s, there are two common ways of storing four-bit BCD digits in those bytes:
A widely used variation of the two-digits-per-byte encoding is called "packed BCD", where numbers end with a sign 'digit', for which the preferred values are 1100 for + and 1101 for −. In packed BCD the number 127 would be represented as the bytes 00010010 01111100, and −127 as 00010010 01111101. While BCD does not make optimal use of storage (about 1/6 of the available memory is not used in packed BCD), conversion to ASCII, EBCDIC, or the various encodings of Unicode is trivial, as no arithmetic operations are required. More dense packings of BCD exist; these avoid the storage penalty and also need no arithmetic operations for common conversions. Unlike pure binary encodings large numbers can easily be displayed by splitting up the Nibble s and sending each to a different character with the logic for each display being a simple mapping function. Converting from pure binary to decimal for display is much harder involving integer multiplication or divide operations. The BIOS in PCs usually keeps the date and time in BCD format, probably for historical reasons (it avoided the need for binary to ASCII conversion). BCD is still in wide use, and Decimal arithmetic is often carried out using BCD or similar encodings. BCD IN ELECTRONICS BCD is very common in electronic systems where a numeric value is to be displayed, especially in systems consisting solely of Digital Logic , and not containing a Microprocessor . By utilising BCD, the manipulation of numerical data for display can be greatly simplified by treating each digit as a separate single sub-circuit. This matches much more closely the physical reality of display hardware—a designer might choose to use a series of separate identical 7-segment Display s to build a metering circuit, for example. If the numeric quantity were stored and manipulated as pure binary, interfacing to such a display would require complex circuitry. Therefore, in cases where the calculations are relatively simple working throughout with BCD can lead to a simpler overall system than converting to 'pure' binary. The same argument applies when hardware of this type uses an embedded Microcontroller or other small processor. Often, smaller code results when representing numbers internally in BCD format, since a conversion from or to binary representation can be expensive on such limited processors. For these applications, some small processors feature BCD arithmetic modes, which assist when writing routines that manipulate BCD quantities. HIGHER-DENSITY ENCODINGS If a decimal digit requires four bits, then three decimal digits require 12 bits. However, since 210>103, if three decimal digits are encoded together then only 10 bits are needed. Two such encodings are '' Chen-Ho Encoding '' and '' Densely Packed Decimal ''. The latter has the advantage that subsets of the encoding encode two digits in the optimal 7 bits and one digit in 4 bits, as in regular BCD. IBM AND BCD IBM used the terms binary-coded decimal and '''BCD''' for six-bit ''alphameric'' codes that represented numbers, upper-case letters and special characters. Some variation of BCD was used in most early IBM computers, including the IBM 1620 , IBM 1400 Series and non- Decimal Architecture members of the IBM 700/7000 Series . With the introduction of System/360 , IBM replaced BCD with 8-bit EBCDIC . Bit positions in BCD were usually labelled ''B, A, 8, 4, 2'' and ''1.'' For encoding digits, ''B'' and ''A'' were zero. The letter A was encoded ''(B,A,1).'' In the 1620 BCD ''alphamerics'' were encoded using digit pairs, with the "zone" in the even digit and the "digit" in the odd digit. Input/Output translation hardware converted between the internal digit pairs and the external standard six-bit BCD codes. In the Decimal Architecture IBM 7070 , IBM 7072 , and IBM 7074 ''alphamerics'' were encoded using digit pairs (using Two-out-of-five Code in the digits, not BCD) of the 10-digit word, with the "zone" in the left digit and the "digit" in the right digit. Input/Output translation hardware converted between the internal digit pairs and the external standard six-bit BCD codes. ADDITION WITH BCD To perform Addition in BCD, you can first add-up in binary format, and then perform the Conversion to BCD afterwards. This conversion involves adding 6 to each group of four digits that has a value of greater-than 9. For example:
However, in binary we cannot have a value greater-than 9 (1001) per-group (" Nybble "). We must therefore add 6 to that group:
which gives us two-groups of four (the groups are every four digits from right-to-left, which themselves are read from left-to-right):
This gives us the 15 in BCD which is the correct result: 0001 is a decimal 1, and 0101 a decimal 5. See also Douglas Jones' Tutorial . BACKGROUND The binary-coded decimal scheme described in this article is the most common encoding, but there are many others. The method here can be referred to as ''Simple Binary-Coded Decimal'' (''SBCD'') or ''BCD 8421''. The '8421' indicates the four bit weights. The following table represents Decimal digits from 0 to 9 in various BCD systems: LEGAL HISTORY In 1972, the U.S. Supreme Court overturned a lower court decision which had allowed a patent for converting BCD encoded numbers to binary on a computer (see Gottschalk v Benson ). This was an important case in determining the patentability of software and algorithms. COMPARISON WITH PURE BINARY Advantages
Disadvantages
SEE ALSO EXTERNAL LINKS REFERENCES
|