Content deleted Content added
Citation bot (talk | contribs) Altered journal. | Use this bot. Report bugs. | Suggested by Qwerfjkl | Linked from User:Qwerfjkl/sandbox/Language-specific_Google_Books_links_2 | #UCB_webform_linked 178/1488 |
m clean up, typo(s) fixed: For example → For example, |
||
Line 1:
{{Short description|System of digitally encoding numbers}}
{{
{{Use dmy dates|date=May 2019|cs1-dates=y}}
{{Use list-defined references|date=January 2022}}
Line 10:
In [[byte]]-oriented systems (i.e. most modern computers), the term ''unpacked'' BCD<ref name="Intel_IA32"/> usually implies a full byte for each digit (often including a sign), whereas ''packed'' BCD typically encodes two digits within a single byte by taking advantage of the fact that four bits are enough to represent the range 0 to 9. The precise four-bit encoding, however, may vary for technical reasons (e.g. [[Excess-3]]).
{{anchor|Pseudo-tetrade}}The ten states representing a BCD digit are sometimes called ''[[tetrade (computing)|tetrade]]s''<ref name="Klar_1970"/><ref name="Klar_1989"/> (the [[nibble]] typically needed to hold them is also known as a tetrade) while the unused, [[don't care]]-states are named {{Interlanguage link
BCD's main virtue, in comparison to binary [[positional system]]s, is its more accurate representation and rounding of decimal quantities, as well as its ease of conversion into conventional<!-- many among us can read hexidecimal just fine, though we don't ordinarily memorize the hexadecimal times table --> human-readable representations. Its principal drawbacks are a slight increase in the complexity of the circuits needed to implement basic arithmetic as well as slightly less dense storage.
BCD was used in many early [[decimal computer]]s, and is implemented in the instruction set of machines such as the [[IBM System/360]] series and its descendants, [[Digital Equipment Corporation]]'s [[VAX]], the [[Burroughs B1700]], and the Motorola [[68000]]-series processors.
BCD ''per se'' is not as widely used as in the past, and is unavailable or limited in newer instruction sets (e.g., [[ARM architecture family|ARM]]; [[x86]] in [[long mode]]). However, decimal [[Fixed-point arithmetic|fixed-point]] and decimal [[floating-point]] formats are still important and continue to be used in financial, commercial, and industrial computing, where the subtle conversion and fractional [[round-off error|rounding errors]] that are inherent in binary floating point formats cannot be tolerated.<ref name="Cowlishaw_GDA" />
Line 360:
==Packed BCD==
<!-- Section header used in redirects -->
In '''packed BCD''' (or '''packed decimal'''<ref name="Dewar-Smosna_1990"/>), each [[nibble]] represents a decimal digit.<ref group="nb" name="Packed_chars"/> Packed BCD has been in use since at least the 1960s and is implemented in all IBM mainframe hardware since then. Most implementations are [[big endian]], i.e. with the more significant digit in the upper half of each byte, and with the leftmost byte (residing at the lowest memory address) containing the most significant digits of the packed decimal value. The lower nibble of the rightmost byte is usually used as the sign flag, although some unsigned representations lack a sign flag.
As an example, a 4-byte value consists of 8 nibbles, wherein the upper 7 nibbles store the digits of a 7-digit decimal value, and the lowest nibble indicates the sign of the decimal integer value. Standard sign values are 1100 ([[hexadecimal|hex]] C) for positive (+) and 1101 (D) for negative (−). This convention comes from the zone field for [[EBCDIC]] characters and the [[signed overpunch]] representation.
Other allowed signs are 1010 (A) and 1110 (E) for positive and 1011 (B) for negative. IBM System/360 processors will use the 1010 (A) and 1011 (B) signs if the A bit is set in the PSW, for the ASCII-8 standard that never passed. Most implementations also provide unsigned BCD values with a sign nibble of 1111 (F).<ref name="IBM_1980_POP"/><ref name="DEC_1983_PDP11"/><ref name="DEC_1985_VAX11"/> ILE RPG uses 1111 (F) for positive and 1101 (D) for negative.<ref name="ILE-RPG"/> These match the EBCDIC zone for digits without a sign overpunch. In packed BCD, the number 127 is represented by 0001 0010 0111 1100 (127C) and −127 is represented by 0001 0010 0111 1101 (127D). Burroughs systems used 1101 (D) for negative, and any other value is considered a positive sign value (the processors will normalize a positive sign to 1100 (C)).
Line 417:
Packed BCD is supported in the [[COBOL]] programming language as the "COMPUTATIONAL-3" (an IBM extension adopted by many other compiler vendors) or "PACKED-DECIMAL" (part of the 1985 COBOL standard) data type. It is supported in [[PL/I]] as "FIXED DECIMAL". Beside the IBM System/360 and later compatible mainframes, packed BCD is implemented in the native instruction set of the original [[VAX]] processors from [[Digital Equipment Corporation]] and some models of the [[SDS Sigma series]] mainframes, and is the native format for the [[Burroughs Medium Systems]] line of mainframes (descended from the 1950s [[Burroughs 205|Electrodata 200 series]]).
[[Ten's complement]] representations for negative numbers offer an alternative approach to encoding the sign of packed (and other) BCD numbers. In this case, positive numbers always have a most significant digit between 0 and 4 (inclusive), while negative numbers are represented by the 10's complement of the corresponding positive number.
As a result, this system allows for 32-bit packed BCD numbers to range from −50,000,000 to +49,999,999, and −1 is represented as 99999999. (As with two's complement binary numbers, the range is not symmetric about zero.)
Line 714:
The Digital Equipment Corporation [[VAX]] series includes [[Instruction set|instructions]] that can perform arithmetic directly on packed BCD data and convert between packed BCD data and other integer representations.<ref name="DEC_1985_VAX11"/> The VAX's packed BCD format is compatible with that on IBM System/360 and IBM's later compatible processors. The MicroVAX and later VAX implementations dropped this ability from the CPU but retained code compatibility with earlier machines by implementing the missing instructions in an operating system-supplied software library. This is invoked automatically via [[exception handling]] when the defunct instructions are encountered, so that programs using them can execute without modification on the newer machines.
Many processors have hardware support for BCD-encoded integer arithmetic. For example, the [[6502]],<ref>{{cite web |url=http://www.masswerk.at/6502/6502_instruction_set.html |title=6502 Instruction Set |archive-url=https://web.archive.org/web/20180508053805/http://www.masswerk.at/6502/6502_instruction_set.html |archive-date=2018-05-08 |url-status=live}}</ref><ref>{{cite web |url=http://www.6502.org/tutorials/6502opcodes.html |title=NMOS 6502 Opcodes |archive-url=https://web.archive.org/web/20160114001557/http://www.6502.org/tutorials/6502opcodes.html |archive-date=2016-01-14}}</ref> the [[Motorola 68000 series]],<ref name="Motorola_m68k"/> and the [[x86]] series.<ref>{{cite book|url= http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf|title= Intel 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture|at= Section 4.7|publisher= Intel|date= March 2013|access-date= April 23, 2013|archive-date= April 2, 2013|archive-url= https://web.archive.org/web/20130402233513/http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf|url-status= live}}</ref> The [[Intel]] x86 architecture supports a [[Intel BCD opcodes|unique 18-digit (ten-byte) BCD format]] that can be loaded into and stored from the floating point registers, from where computations can be performed.<ref name="Intel_2020_V1"/>
In more recent computers such capabilities are almost always implemented in software rather than the CPU's instruction set, but BCD numeric data are still extremely common in commercial and financial applications.
Line 737:
{{Multiple issues|section=true|{{More citations needed section|date=January 2018}}{{Primary sources|section|date=January 2018}}}}
BCD is 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 employing 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 [[seven-segment display]]s to build a metering circuit, for example. If the numeric quantity were stored and manipulated as pure binary, interfacing with such a display would require complex circuitry. Therefore, in cases where the calculations are relatively simple, working throughout with BCD can lead to an overall simpler system than converting to and from binary. Most pocket calculators do all their calculations in BCD.
Line 746:
<!-- not at all clear why this needs to be here at all, shouldn't the article just describe BCD? (mfc)-->
<!--as an alternative number system for computing and electronics imo a comparison to the standard one is justified (plugwash)-->
=== Advantages ===
* Scaling by a power of 10 is simple.
* [[Rounding]] at a decimal digit boundary is simpler. Addition and subtraction in decimal do not require rounding.{{dubious|Rounding|date=November 2021}}
* The 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, and can be done in linear ([[Big-O notation|O]](''n'')) time. Conversion from pure [[binary number|binary]] involves relatively complex logic that spans digits, and for large numbers, no linear-time conversion algorithm is known (see {{
* Many non-integral values, such as decimal 0.2, have an infinite place-value representation in binary (.001100110011...) but have a finite place-value in binary-coded decimal (0.0010). Consequently, a system based on binary-coded decimal representations of decimal fractions avoids errors representing and calculating such values. This is useful in financial calculations.
Line 842 ⟶ 843:
==Legal history==
In the 1972 case ''[[Gottschalk v. Benson]]'', the [[U.S. Supreme Court]] overturned a [[United States Court of Customs and Patent Appeals|lower court]]'s decision that had allowed a [[patent]] for converting BCD-encoded numbers to binary on a computer.
The decision noted that a patent "would wholly pre-empt the mathematical formula and in practical effect would be a patent on the [[algorithm]] itself".<ref name="Gottschalk-Benson_1972" /> This was a landmark judgement that determined the [[Software patents under United States patent law|patentability of software and algorithms]].
Line 890 ⟶ 891:
<ref name="Savard_2018_Decimal">{{cite web |title=Decimal Representations |author-first=John J. G. |author-last=Savard |date=2018 |orig-date=2006 |work=quadibloc |url=http://www.quadibloc.com/comp/cp0203.htm |access-date=2018-07-16 |url-status=live |archive-url=https://web.archive.org/web/20180716101321/http://www.quadibloc.com/comp/cp0203.htm |archive-date=2018-07-16}}</ref>
<ref name="Yuen_1977">{{cite journal |title=A New Representation for Decimal Numbers |author-first=Chun-Kwong |author-last=Yuen |journal=[[IEEE Transactions on Computers]] |date=December 1977 |volume=C-26 |issue=12 |doi=10.1109/TC.1977.1674792 |s2cid=40879271 |pages=1286–1288 |url=https://dl.acm.org/doi/10.1109/TC.1977.1674792 |access-date=2020-08-08 |url-status=live |archive-url=https://web.archive.org/web/20200808105531/https://dl.acm.org/doi/10.1109/TC.1977.1674792 |archive-date=2020-08-08}}</ref>
<ref name="Kautz_1954">{{cite conference |title=Optimized Data Encoding for Digital Computers |chapter=IV. Examples A. Binary Codes for Decimals, n = 4 |author-last=Kautz |author-first=William H. |author-link=William H. Kautz |conference=Convention Record of the I.R.E., 1954 National Convention, Part 4 - Electronic Computers and Information Theory |publisher=[[I.R.E.]] |series=Session 19: Information Theory III - Speed and Computation |date=June 1954 |___location=Stanford Research Institute, Stanford, California, USA |pages=47–57 [49, 51–52, 57] |url=https://worldradiohistory.com/Archive-IRE/50s/IRE-1954-Part-4-Electronic-Computers-&-Information%20pdf |access-date=2020-07-03 |url-status=live |archive-url=https://web.archive.org/web/20200703180632/https://worldradiohistory.com/Archive-IRE/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information%20pdf |archive-date=2020-07-03 |quote-page=52 |quote=[…] The last column [of Table II], labeled "Best," gives the maximum fraction possible with any code—namely 0.60—half again better than any conventional code. This extremal is reached with the ten
<ref name="Lippel_1955">{{cite journal |title=A Decimal Code for Analog-to-Digital Conversion |author-last=Lippel |author-first=Bernhard |journal=[[IRE Transactions on Electronic Computers]] |issn=0367-9950 |volume=EC-4 |issue=4 |date=December 1955 |doi=10.1109/TEC.1955.5219487 |pages=158–159}} (2 pages)</ref>
<ref name="Stopper_1960">{{cite journal |title=Ermittlung des Codes und der logischen Schaltung einer Zähldekade |language=de |author-first=Herbert |author-last=Stopper |editor-first=Wilhelm Tolmé |editor-last=Runge |editor-link=Wilhelm Tolmé Runge |date=March 1960 |journal=Telefunken-Zeitung (TZ) - Technisch-Wissenschaftliche Mitteilungen der Telefunken GMBH |volume=33 |issue=127 |publisher=[[Telefunken]] |publication-place=Berlin, Germany |___location=Litzelstetten, Germany |pages=13–19}} (7 pages<!-- of total pages 1–80 -->)</ref>
|