Content deleted Content added
BMarie 212 (talk | contribs) |
BMarie 212 (talk | contribs) m →Legal history: Structural edits to follow a consistent organization of information |
||
Line 14:
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" /> =={{anchor|Unpacked BCD|NBCD|8421|8-4-2-1}}Background==
Line 358 ⟶ 360:
==Packed BCD==
<!-- Section header used in redirects -->
In '''packed BCD''' (or '''packed decimal'''<ref name="Dewar-Smosna_1990"/>), each [[nibble]] represent 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 413 ⟶ 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 Corporation]] 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.) ===Fixed-point packed decimal===
Line 644 ⟶ 650:
===Fixed-point zoned decimal===
Some languages (such as COBOL and PL/I) directly support fixed-point zoned decimal values, assigning 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 fourth digit, the hex bytes F1 F2 F7 F9 F5 C0 represent the value +1,279.50: F1 F2 F7 F9 F5 C0
1 2 7 9. 5 +0
Line 672 ⟶ 680:
The [[Motorola 68000 series]] had BCD instructions.<ref name="Motorola_m68k"/>
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.
There are tricks for implementing packed BCD and zoned decimal add–or–subtract operations using short but difficult to understand sequences of word-parallel logic and binary arithmetic operations.<ref name="Jones_1999_AT" /> For example, the following code (written in [[C (programming language)|C]]) computes an unsigned 8-digit packed BCD addition using 32-bit binary operations: <syntaxhighlight lang="c">
uint32_t BCDadd(uint32_t a, uint32_t b)
Line 691 ⟶ 701:
{{Multiple issues|section=true|{{More citations needed section|date=January 2018}}{{Primary sources|section|date=January 2018}}}}
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 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. The same argument applies when hardware of this type uses an embedded microcontroller or other small processor. Often, representing numbers internally in BCD format results in smaller code, since a conversion from or to binary representation can be expensive on such limited processors. For these applications, some small processors feature dedicated arithmetic modes, which assist when writing routines that manipulate BCD quantities.<ref name="IEEE_CORDIC"/><ref name="BCS_CORDIC"/>
Line 832 ⟶ 844:
==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]]. ==See also==
|