Information about Binary Coded Decimal
In computing and electronic systems, binary-coded decimal (BCD) is an encoding for decimal numbers in which each digit is represented by its own binary sequence. Its main virtue is that it allows easy conversion to decimal digits for printing or display and faster decimal calculations. Its drawbacks are the increased complexity of circuits needed to implement mathematical operations and a relatively inefficient encoding – 6 wasted patterns per digit. Even though the importance of BCD has diminished , it is still widely used in financial, commercial, and industrial applications.
In BCD, a digit is usually represented by four bits which, in general, represent the values/digits/characters 0-9. Other bit combinations are sometimes used for sign or other indications.
Decimal: 0 1 2 3 4 5 6 7 8 9 BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Thus, the BCD encoding for the number 127 would be:
0001 0010 0111
Since most computers store data in eight-bit bytes, there are two common ways of storing four-bit BCD digits in those bytes:
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.
Packing four-bit digits and a sign into eight-bit bytes means that an n-byte packed decimal value (where n typically ranges from 1 to 15) contains 2n−1 decimal digits (which is always an odd number of digits). In other words, d decimal digits require a packed decimal representation that is (d+1)/2 bytes wide. For example, a four-byte packed decimal number holds seven decimal digits plus a sign, and can represent values from ±0,000,000 to ±9,999,999.
While packed BCD does not make optimal use of storage (about 1/6 of the available memory is wasted), conversion to ASCII, EBCDIC, or the various encodings of Unicode is still trivial, as no arithmetic operations are required. The extra storage requirements are usually offset by the need for the accuracy that fixed-point decimal arithmetic provides. More dense packings of BCD exist which avoid the storage penalty and also need no arithmetic operations for common conversions.
For signed zoned decimal values, the rightmost (least significant) zone nibble holds the sign digit, which is the same set of values that are used for signed packed decimal numbers (see above). Thus a zoned decimal value encoded as the hex bytes F1 F2 D3 represents the signed decimal value −123.
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.
Today, BCD is still heavily used in IBM processors and databases, such as IBM DB2, mainframes and Power6. In these products, the BCD is usually zoned BCD (as in EBCDIC or ASCII), Packed BCD, or 'pure' BCD encoding. All of these are used in within hardware registers and processing units and in software.
See also Douglas Jones' Tutorial.
The following table represents decimal digits from 0 to 9 in various BCD systems:
In BCD, a digit is usually represented by four bits which, in general, represent the values/digits/characters 0-9. Other bit combinations are sometimes used for sign or other indications.
Basics
To BCD-encode a decimal number using the common encoding, each decimal digit is stored in a four-bit nibble.Decimal: 0 1 2 3 4 5 6 7 8 9 BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Thus, the BCD encoding for the number 127 would be:
0001 0010 0111
Since most computers store data in eight-bit bytes, there are two common ways of storing four-bit BCD digits in those bytes:
- each digit is stored in one byte, and the other four bits are then set to all zeros, all ones (as in the EBCDIC code), or to 0011 (as in the ASCII code)
- two digits are stored in each byte.
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 displays 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.
Packed BCD
A widely used variation of the two-digits-per-byte encoding is called packed BCD (or simply packed decimal), where numbers are stored with two decimal digits "packed" into one byte each, and the last digit (or nibble) is used as a sign indicator. The preferred sign values are 1100 (hex C) for positive (+) and 1101 (hex D) for negative (−); other allowed signs are 1010 (A) and 1110 (E) for positive and 1011 (B) for negative. Some implementations also provide unsigned BCD values with a sign nibble of 1111 (hex F). In packed BCD, the number +127 is represented as the bytes 00010010 01111100 (hex 12 7C), and −127 as 00010010 01111101 (hex 12 7D).| Sign Digit |
BCD 8 4 2 1 |
Sign |
|---|---|---|
| A | 1 0 1 0 | + |
| B | 1 0 1 1 | − |
| C | 1 1 0 0 | + (preferred) |
| D | 1 1 0 1 | − (preferred) |
| E | 1 1 1 0 | + |
| F | 1 1 1 1 | + (unsigned) |
Packing four-bit digits and a sign into eight-bit bytes means that an n-byte packed decimal value (where n typically ranges from 1 to 15) contains 2n−1 decimal digits (which is always an odd number of digits). In other words, d decimal digits require a packed decimal representation that is (d+1)/2 bytes wide. For example, a four-byte packed decimal number holds seven decimal digits plus a sign, and can represent values from ±0,000,000 to ±9,999,999.
While packed BCD does not make optimal use of storage (about 1/6 of the available memory is wasted), conversion to ASCII, EBCDIC, or the various encodings of Unicode is still trivial, as no arithmetic operations are required. The extra storage requirements are usually offset by the need for the accuracy that fixed-point decimal arithmetic provides. More dense packings of BCD exist which avoid the storage penalty and also need no arithmetic operations for common conversions.
Fixed-point packed decimal
Fixed-point decimal numbers are supported by some programming languages (such as COBOL and PL/1), and provide an implicit decimal point in front of one of the digits. For example, a packed decimal value encoded with the bytes 12 34 56 7C represents the fixed-point value +1,234.567 when the implied decimal point is located between the 4th and 5th digits.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.Zoned decimal
Some implemenatations (notably IBM mainframe systems) support zoned decimal numeric representations. Each decimal digit is stored in one byte, with the lower four bits encoding the digit in BCD form. The upper four bits, called the "zone" bits, are usually set to a fixed value so that the byte holds a character value corresponding to the digit. EBCDIC systems use a zone value of 1111 (hex F); this yields bytes in the range F0 to F9 (hex), which are the EBCDIC codes for the characters "0" through "9". Similarly, ASCII systems use a zone value of 0011 (hex 3), giving character codes 30 to 39 (hex).For signed zoned decimal values, the rightmost (least significant) zone nibble holds the sign digit, which is the same set of values that are used for signed packed decimal numbers (see above). Thus a zoned decimal value encoded as the hex bytes F1 F2 D3 represents the signed decimal value −123.
Fixed-point zone decimal
Some languages (such as COBOL and PL/1) directly support fixed-point zoned decimal values, assiging an implicit decimal point at some location between the decimal digits of a number. For example, given a six-byte signed zoned decimal value with an implied decimal point to the right of the 4th digit, the hex bytes F1 F2 F7 F9 F5 C0 represent the value +1,279.50.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.
Today, BCD is still heavily used in IBM processors and databases, such as IBM DB2, mainframes and Power6. In these products, the BCD is usually zoned BCD (as in EBCDIC or ASCII), Packed BCD, or 'pure' BCD encoding. All of these are used in within hardware registers and processing units and in software.
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:- 9+5=14 = [1001] + [0101] = [1110] in binary.
- [0000 1110] + [0000 0110] = [0001 0100]
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. In the headers to the table, the '8 4 2 1' indicates the four bit weights; note that in the 5th column two of the weights are negative.The following table represents decimal digits from 0 to 9 in various BCD systems:
| Digit | BCD 8 4 2 1 |
Excess-3 or Stibitz Code |
BCD 2 4 2 1 or Aiken Code |
BCD 8 4 −2 −1 |
IBM 702 IBM 705 IBM 7080 IBM 1401 8 4 2 1 |
|---|---|---|---|---|---|
| 0 | 0000 | 0011 | 0000 | 0000 | 1010 |
| 1 | 0001 | 0100 | 0001 | 0111 | 0001 |
| 2 | 0010 | 0101 | 0010 | 0110 | 0010 |
| 3 | 0011 | 0110 | 0011 | 0101 | 0011 |
| 4 | 0100 | 0111 | 0100 | 0100 | 0100 |
| 5 | 0101 | 1000 | 1011 | 1011 | 0101 |
| 6 | 0110 | 1001 | 1100 | 1010 | 0110 |
| 7 | 0111 | 1010 | 1101 | 1001 | 0111 |
| 8 | 1000 | 1011 | 1110 | 1000 | 1000 |
| 9 | 1001 | 1100 | 1111 | 1111 | 1001 |
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
- Scaling by a factor of 10 (or a power of 10) is simple; this is useful when a decimal scaling factor is needed to represent a non-integer quantity (e.g., in financial calculations where it is required that a computer get the same result that a human would)
- Rounding at a decimal digit boundary is easier
- Alignment of two decimal numbers (for example 1.3 + 27.08) is a simple, exact, shift
- Conversion to a character form or for display (e.g., to a text-based format such as XML, or to drive signals for a seven-segment display) is a simple per-digit mapping (conversion from pure binary involves relatively complex logic that spans digits, and gets geometrically worse as the length of the number increases).
- If used for decimals, allows exact representation of decimals, compared to approximation to the closest power of two.
Disadvantages
- Some operations are more complex to implement. Adders require extra logic to cause them to wrap and generate a carry early. 15%-20% more circuitry is needed for BCD add compared to pure binary. Multiplication requires the use of algorithms that are somewhat more complex than shift-mask-add (a binary multiplication, requiring binary shifts and adds or the equivalent, per-digit or group of digits is required)
- BCD in raw form requires four bits per digit. However, when packed so that three digits are encoded in ten bits, the extra storage requirement over pure binary is insignificant for most applications.
Representational variations
Various BCD implementations exist that employ other representations for numbers. Programmable calculators manufactured by Texas Instruments, Hewlett-Packard, and others typically employ a floating-point BCD format, typically with two or three digits for the (decimal) exponent. The extra bits of the sign digit may be used to indicate special numeric values, such as infinity, underflow/overflow, and error (a blinking display).See also
External links
References
- Arithmetic Operations in Digital Computers, R. K. Richards, 397pp, D. Van Nostrand Co., NY, 1955
- Schmid, Hermann, Decimal computation, ISBN 047176180X, 266pp, Wiley, 1974
- Superoptimizer: A Look at the Smallest Program, Henry Massalin, ACM Sigplan Notices, Vol. 22 #10 (Proceedings of the Second International Conference on Architectual support for Programming Languages and Operating Systems), pp122-126, ACM, also IEEE Computer Society Press #87CH2440-6, October 1987
- VLSI designs for redundant binary-coded decimal addition, Behrooz Shirazi, David Y. Y. Yun, and Chang N. Zhang, IEEE Seventh Annual International Phoenix Conference on Computers and Communications, 1988, pp52-56, IEEE, March 1988
- Fundamentals of Digital Logic by Brown and Vranesic, 2003
- Modified Carry Look Ahead BCD Adder With CMOS and Reversible Logic Implementation, Himanshu Thapliyal and Hamid R. Arabnia, Proceedings of the 2006 International Conference on Computer Design (CDES'06), ISBN 1-60132-009-4, pp64-69, CSREA Press, November 2006
- Reversible Implementation of Densely-Packed-Decimal Converter to and from Binary-Coded-Decimal Format Using in IEEE-754R, A. Kaivani, A. Zaker Alhosseini, S. Gorgin, and M. Fazlali, 9th International Conference on Information Technology (ICIT'06), pp273-276, IEEE, December 2006.
computing is synonymous with counting and calculating. Originally, people that performed these functions were known as computers. Today it refers to a science and technology that deals with the computation and the manipulation of symbols.
..... Click the link for more information.
..... Click the link for more information.
Electronics is the study of the flow of charge through various materials and devices such as, semiconductors, resistors, inductors, capacitors, nano-structures, and vacuum tubes. All applications of electronics involve the transmission of power and possibly information.
..... Click the link for more information.
..... Click the link for more information.
digit is a symbol (a number symbol, e.g. "3" or "7") used in numerals (combinations of symbols, e.g. "37"), to represent numbers, (integers or real numbers) in positional numeral systems.
..... Click the link for more information.
..... Click the link for more information.
BIT is an acronym for:
..... Click the link for more information.
- Bannari amman Institute of Technology
- Bangalore Institute of Technology
- Beijing Institute of Technology
- Benzisothiazolinone
- Bilateral Investment Treaty
- Bhilai Institute of Technology - Durg
..... Click the link for more information.
nibble (or less commonly, nybble) is the computing term for a four-bit aggregation[1], or half an octet (an octet being an 8-bit byte). As a nibble contains 4 bits, there are sixteen (24
..... Click the link for more information.
..... Click the link for more information.
byte (pronounced /baɪt/) is a unit of measurement of information storage, most often consisting of eight bits. In many computer architectures it is a unit of memory addressing.
..... Click the link for more information.
..... Click the link for more information.
Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8-bit character encoding (code page) used on IBM mainframe operating systems, like z/OS, OS/390, VM and VSE, as well as IBM minicomputer operating systems like OS/400 and i5/OS (see also Binary Coded Decimal).
..... Click the link for more information.
..... Click the link for more information.
American Standard Code for Information Interchange (ASCII), generally pronounced ask-ee IPA: /ˈæski/ ( [1] ), is a character encoding based on the English alphabet.
..... Click the link for more information.
..... Click the link for more information.
Bios or BIOS may refer to:
..... Click the link for more information.
- Life (in Greek, βίος/Bios)
- Biographies, a genre of literature/media based on accounts of people's lives
..... Click the link for more information.
Digital electronics are electronics systems that use digital signals. Digital electronics are representations of Boolean algebra and are used in computers, mobile phones, and other consumer products.
..... Click the link for more information.
..... Click the link for more information.
Microprocessor
Die of an Intel 80486DX2 microprocessor (actual size: 12×6.75 mm) in its packaging
Date Invented: Late 1960s/Early 1970s (see article for explanation)
Connects to:
..... Click the link for more information.
Die of an Intel 80486DX2 microprocessor (actual size: 12×6.75 mm) in its packaging
Date Invented: Late 1960s/Early 1970s (see article for explanation)
Connects to:
..... Click the link for more information.
seven-segment display (abbreviation: "7-seg(ment) display"), less commonly known as a seven-segment indicator, is a form of display device that is an alternative to the more complex dot-matrix displays.
..... Click the link for more information.
..... Click the link for more information.
microcontroller (or MCU) is a computer-on-a-chip. It is a type of microprocessor emphasizing self-sufficiency and cost-effectiveness, in contrast to a general-purpose microprocessor (the kind used in a PC).
..... Click the link for more information.
..... Click the link for more information.
nibble (or less commonly, nybble) is the computing term for a four-bit aggregation[1], or half an octet (an octet being an 8-bit byte). As a nibble contains 4 bits, there are sixteen (24
..... Click the link for more information.
..... Click the link for more information.
hexadecimal, base-16, or simply hex, is a numeral system with a radix, or base, of 16, usually written using the symbols 0–9 and A–F, or a–f.
..... Click the link for more information.
..... Click the link for more information.
American Standard Code for Information Interchange (ASCII), generally pronounced ask-ee IPA: /ˈæski/ ( [1] ), is a character encoding based on the English alphabet.
..... Click the link for more information.
..... Click the link for more information.
Extended Binary Coded Decimal Interchange Code (EBCDIC) is an 8-bit character encoding (code page) used on IBM mainframe operating systems, like z/OS, OS/390, VM and VSE, as well as IBM minicomputer operating systems like OS/400 and i5/OS (see also Binary Coded Decimal).
..... Click the link for more information.
..... Click the link for more information.
Unicode is an industry standard allowing computers to consistently represent and manipulate text expressed in any of the world's writing systems. Developed in tandem with the Universal Character Set standard and published in book form as The Unicode Standard
..... Click the link for more information.
..... Click the link for more information.
COBOL
Paradigm: multi-paradigm
Appeared in: 1959
Designed by: Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E.
..... Click the link for more information.
Paradigm: multi-paradigm
Appeared in: 1959
Designed by: Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E.
..... Click the link for more information.
PL/I
Paradigm: imperative, structured
Appeared in: 1964
Designed by: Hursley Laboratories
Developer: IBM
Dialects: PL/M, XPL, PL/P, PL/C, PL/S, PL/AS, PL/X, PL/8, EPL
Influenced by: COBOL, Fortran, ALGOL,
PL/I
..... Click the link for more information.
Paradigm: imperative, structured
Appeared in: 1964
Designed by: Hursley Laboratories
Developer: IBM
Dialects: PL/M, XPL, PL/P, PL/C, PL/S, PL/AS, PL/X, PL/8, EPL
Influenced by: COBOL, Fortran, ALGOL,
PL/I
..... Click the link for more information.
Chen-Ho encoding is an alternate system of binary encoding for decimal digits.
The traditional system of binary encoding for decimal digits, known as Binary-coded decimal (BCD), uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth
..... Click the link for more information.
The traditional system of binary encoding for decimal digits, known as Binary-coded decimal (BCD), uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth
..... Click the link for more information.
Densely Packed Decimal (DPD) is a system of binary encoding for decimal digits.
The traditional system of binary encoding for decimal digits, known as Binary-coded decimal (BCD), uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth
..... Click the link for more information.
The traditional system of binary encoding for decimal digits, known as Binary-coded decimal (BCD), uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth
..... Click the link for more information.
International Business Machines Corporation
Public (NYSE: IBM )
Founded 1889, incorporated 1911
Headquarters Armonk, New York, USA
Key people Samuel J.
..... Click the link for more information.
Public (NYSE: IBM )
Founded 1889, incorporated 1911
Headquarters Armonk, New York, USA
Key people Samuel J.
..... Click the link for more information.
COBOL
Paradigm: multi-paradigm
Appeared in: 1959
Designed by: Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E.
..... Click the link for more information.
Paradigm: multi-paradigm
Appeared in: 1959
Designed by: Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E.
..... Click the link for more information.
PL/I
Paradigm: imperative, structured
Appeared in: 1964
Designed by: Hursley Laboratories
Developer: IBM
Dialects: PL/M, XPL, PL/P, PL/C, PL/S, PL/AS, PL/X, PL/8, EPL
Influenced by: COBOL, Fortran, ALGOL,
PL/I
..... Click the link for more information.
Paradigm: imperative, structured
Appeared in: 1964
Designed by: Hursley Laboratories
Developer: IBM
Dialects: PL/M, XPL, PL/P, PL/C, PL/S, PL/AS, PL/X, PL/8, EPL
Influenced by: COBOL, Fortran, ALGOL,
PL/I
..... Click the link for more information.
International Business Machines Corporation
Public (NYSE: IBM )
Founded 1889, incorporated 1911
Headquarters Armonk, New York, USA
Key people Samuel J.
..... Click the link for more information.
Public (NYSE: IBM )
Founded 1889, incorporated 1911
Headquarters Armonk, New York, USA
Key people Samuel J.
..... Click the link for more information.
The IBM 1620 was announced by IBM on October 21, 1959 and marketed as an inexpensive "scientific computer". After a total production of about two thousand machines, it was withdrawn on November 19, 1970.
..... Click the link for more information.
..... Click the link for more information.
The IBM 1400 series were second generation (transistorized) mid-range business computers that IBM sold in the early 1960s. They could be operated as an independent systems, in conjunction with IBM punched card equipment, or as auxiliary equipment to other computer systems.
..... Click the link for more information.
..... Click the link for more information.
IBM 700/7000 series was a series of large scale (mainframe) computer systems made by IBM through the 1950s and early 1960s. The series included several different, incompatible processor architectures.
..... Click the link for more information.
..... Click the link for more information.
System/360 Model 65 operator's console, with register value lamps and toggle switches (middle of picture) and "emergency pull" switch (upper right).]] The IBM System/360 (S/360) is a mainframe computer system family announced by IBM on April 7, 1964.
..... Click the link for more information.
..... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus