Binary-coded decimal: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Removed URL that duplicated identifier. Removed parameters. | Use this bot. Report bugs. | Suggested by Headbomb | Linked from Wikipedia:WikiProject_Academic_Journals/Journals_cited_by_Wikipedia/Sandbox | #UCB_webform_linked 279/1032
 
(11 intermediate revisions by 8 users not shown)
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|pseudo-tetrade|de|3=Pseudotetrade|lt=''pseudo-tetrad(e)s''{{small|{{bracket|[[:de:Pseudotetrade|de]]}}}},<ref name="Schneider_1986"/><ref name="Tafel_1971"/><ref name="Steinbuch-Weber-Heinemann_1974"/><ref name="Tietze-Schenk_2013"/><ref name="Kowalski_1070"/> ''pseudo-decimals'',<ref name="Klar_1989"/> or ''pseudo-decimal digits''.<ref name="Ferretti_2013"/><ref name="Speiser_1965"/><ref group="nb" name="Pseudo-tetrades"/>
 
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.
Line 360:
==Packed BCD==
<!-- Section header used in redirects -->
InSome computers whose words are multiples of an [[Octet (computing)|octet]] (8-bit byte), for example contemporary IBM mainframe systems, support '''packed BCD''' (or '''packed decimal'''<ref name="Dewar-Smosna_1990"/>) numeric representations, in which each [[nibble]] represents either a decimal digit or a sign.<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.
Line 403:
|}
 
No matter how many bytes wide a [[Word (datacomputer typearchitecture)|word]] is, there is always an even number of nibbles because each byte has two of them. Therefore, a word of ''n'' bytes can contain up to (2''n'')−1 decimal digits, which is always an odd number of digits. A decimal number with ''d'' digits requires {{sfrac|1|2}}(''d''+1) bytes of storage space.
 
For example, a 4-byte (32-bit) word can hold seven decimal digits plus a sign and can represent values ranging from ±9,999,999. Thus the number −1,234,567 is 7 digits wide and is encoded as:
Line 434:
 
=={{anchor|Zoned BCD}}Zoned decimal==
Some implementations, for example [[IBM]] mainframe systems, support '''zoned decimal''' numeric representations. Each decimal digit is stored in one 8-bit<ref group=nb>6-bit for older machines.</ref> byte, with the lower four bits encoding the digit in BCD form. The upper four<ref group=nb>Two for older machines.</ref> bits, called the "zone" bits, are usually set to a fixed value so that the byte holds a character value corresponding to the digit, or to values representing plus or minus. EBCDIC<ref group=nb>The values shown for {{base|C0|16}} and {{base|D0|16}} are for code page 037.</ref> systems use a zone value of {{base|1111|2}} (hex {{base|F|16}});, thisyielding yields{{base|F0|16}}-{{base|F9|16}}, bytesthe incodes thefor range"0" F0through to"9", F9a zone value of {{base|1100|2}} (hex{{base|C|16}}) for positive, whichyielding are{{base|C0|16}}-{{base|C9|16}}, the EBCDICcodes for "{" through "I" and a zone value of {{base|1110|2}} ({{base|D|16}}) for negative, yielding {{base|D0|16}}-{{base|D9|16}}, the codes for the characters "0}" through "9R". 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:
Line 756:
=== Disadvantages ===
* Practical existing implementations of BCD are typically slower than operations on binary representations, especially on embedded systems, due to limited processor support for native BCD operations.<ref name="Mathur_1989" />
* Some operations are more complex to implement. [[Adder (electronics)|Adder]]s require extra logic to cause them to wrap and generate a carry early. Also, 15 to 20 per cent% more circuitry is needed for BCD add compared to pure binary.{{Citation needed|date=May 2011}} Multiplication requires the use of algorithms that are somewhat more complex than shift-mask-add (a [[Binary numeral system#Multiplication|binary multiplication]], requiring binary shifts and adds or the equivalent, per-digit or group of digits is required).
* Standard BCD requires four bits per digit, roughly 20 per cent% more space than a binary encoding (the ratio of 4 bits to log<sub>2</sub>10 bits is 1.204). When packed so that three digits are encoded in ten bits, the storage overhead is greatly reduced, at the expense of an encoding that is unaligned with the 8-bit byte boundaries common on existing hardware, resulting in slower implementations on these systems.<!-- Could add: encoding or decoding is trivial in software using a table lookup, and fast using direct logic otherwise. In hardware, it requires no more than three gate delays. -->
 
==Representational variations==
Line 792:
 
==={{anchor|TBCD}}Telephony binary-coded decimal (TBCD)===
[[3GPP]] developed '''TBCD''',<ref name="3GPP_2013_TS29002"/> an expansion to BCD where the remaining (unused) bit combinations are used to add specific [[telephony]] characterssymbols,<ref name="ETSI_SPS"/><ref name="OpenSS_XMAP"/> with digits similar to those found in [[DTMF|telephone keypad]]s original design.
{| class="wikitable" style="width:30%; text-align:center"
|-
Line 890:
<ref name="Dewar-Smosna_1990">{{cite book |title=Microprocessors - A Programmer's View |author-first1=Robert Berriedale Keith |author-last1=Dewar |author-link1=Robert Berriedale Keith Dewar |author-first2=Matthew |author-last2=Smosna |date=1990 |edition=1 |publisher=[[McGraw-Hill Publishing Company]] |___location=[[Courant Institute]], [[New York University]], New York, USA |isbn=0-07-016638-2 |lccn=89-77320 |page=14}} (xviii+462 pages)</ref>
<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|url-access=subscription }}</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 heavily-marked vertices of the graph of [[#Kautz|Fig. 4]] for n = 4, or, in fact, with any set of ten code combinations which include all eight with an even (or all eight with an odd) number of "1's." The second and third rows of Table II list the average and peak decimal change per undetected single binary error, and have been derived using the equations of Sec. II for Δ<sub>1</sub> and δ<sub>1</sub>. The confusion index for decimals using the criterion of "decimal change," is taken to be c<sub>ij</sub> = {{!}}i − j{{!}} &nbsp; i,j = 0, 1, … 9. Again, the "Best" arrangement possible (the same for average and peak), one of which is shown in Fig. 4, is substantially better than the conventional codes. […] Fig. 4 [[#Kautz|Minimum-confusion code for decimals]]. […] δ<sub>1</sub>=2 &nbsp; Δ<sub>1</sub>=15 […]}} [https://web.archive.org/web/20200703173707/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0049.pdf] [https://web.archive.org/web/20200703175038/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0050.pdf] [https://web.archive.org/web/20200703175214/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0051.pdf] [https://web.archive.org/web/20200703175243/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0052.pdf] [https://web.archive.org/web/20200703175313/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0053.pdf] [https://web.archive.org/web/20200703175344/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0054.pdf] [https://web.archive.org/web/20200703175425/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0055.pdf] [https://web.archive.org/web/20200703175459/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0056.pdf] [https://web.archive.org/web/20200703175529/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0057.pdf] [https://web.archive.org/web/20200703175606/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0058.pdf] [https://web.archive.org/web/20200703175641/https://worldradiohistory.com/hd2/IDX-Site-Technical/Engineering-General/Archive-IRE-IDX/IDX/50s/IRE-1954-Part-4-Electronic-Computers-%26-Information-OCR-Page-0059.pdf] (11 pages) (NB. Besides the combinatorial set of 4-bit BCD "minimum-confusion codes for decimals", of which the author illustrates only one explicitly (here reproduced as [[#Kautz|code I]]) in form of a 4-bit graph, the author also shows a 16-state 4-bit "binary code for analog data" in form of a code table, which, however, is not discussed here. The [[#Kautz II|code II]] shown here is a modification of code I discussed by {{citeref|Berger|1962|Berger|style=plain}}.)</ref>
<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>
Line 899:
<ref name="Glixon_1957">{{cite journal |date=March 1957 |title=Can You Take Advantage of the Cyclic Binary-Decimal Code? |author-first=Harry Robert |author-last=Glixon |journal=[[Control Engineering (magazine)|Control Engineering]] |issn=0010-8049 |publisher=[[Technical Publishing Company]], a division of Dun-Donnelley Publishing Corporation, [[Dun & Bradstreet Corp.]] |volume=4 |number=3 |pages=<!-- 3, -->87–91 |url=https://books.google.com/books?id=-_5IAQAAIAAJ}}<!-- https://web.archive.org/web/20180115014809/https://donmooreswartales.com/2010/05/12/harry-glixon/ https://books.google.com/books?id=-_5IAQAAIAAJ&focus=searchwithinvolume&q=cyclic+binary+code --> (5 pages)</ref>
<ref name="White_1953">{{cite journal |title=Coded Decimal Number Systems for Digital Computers |author-first=Garland S. |author-last=White |journal=[[Proceedings of the Institute of Radio Engineers]] |publisher=[[Institute of Radio Engineers]] (IRE) |issn=0096-8390 |eissn=2162-6634 |volume=41 |number=10 |date=October 1953 |doi=10.1109/JRPROC.1953.274330 |s2cid=51674710 |pages=1450–1452}} (3 pages)</ref>
<ref name="Lucal_1959">{{cite journal |author-first=Harold M. |author-last=Lucal |title=Arithmetic Operations for Digital Computers Using a Modified Reflected Binary |journal=[[IRE Transactions on Electronic Computers]] |volume=EC-8 |number=4 |pages=449–458 |date=December 1959 |issn=0367-9950 |doi=10.1109/TEC.1959.5222057 |s2cid=206673385 |url=https://ieeexplore.ieee.org/document/5222057}} (10 pages)</ref>
<ref name="EHub_2015">{{cite web |title=Different Types of Binary Codes |at=Section 2.4 5211 Code |date=2019-05-01 |orig-date=2015-01-28 |work=Electronic Hub |url=https://www.electronicshub.org/disclaimer/ |access-date=2020-08-04 |url-status=live |archive-url=https://web.archive.org/web/20200518203953/https://www.electronicshub.org/disclaimer/ |archive-date=2020-05-18}}</ref>
<ref name="Paul_1995">{{cite web |author-first=Matthias R. |author-last=Paul |title=Unterbrechungsfreier Schleifencode |language=de |trans-title=Continuous loop code |version=1.02 |url=http://www.uni-bonn.de/~uzs180/download/mpbcd102.zip |date=1995-08-10 |orig-date=1994 |access-date=2008-02-11}}{{cbignore}} (NB. The author called this code {{lang|de|Schleifencode}} (English: "loop code"). It differs from [[Gray BCD code]] only in the encoding of state 0 to make it a cyclic [[unit-distance code]] for full-circle rotatory [[slip ring]] applications. Avoiding the all-zero code pattern allows for loop self-testing and to use the data lines for uninterrupted power distribution.)</ref>