Binary-coded decimal: Difference between revisions

Content deleted Content added
tweak english etc.
Line 1:
'''Binary coded decimal''' (BCD) is a [[numeral system]] used in computer memory[[computing]] and in [[electronics]] systems. In BCD, numbers are represented as a sequence of decimal digits, andin which each digit is represented by four [[bit]]s:
 
Digit Bits Digit Bits
Line 7:
'''3''' 0011 '''8''' 1000
'''4''' 0100 '''9''' 1001
To encode a number such as 127, then, one simply encodes each of the decimal digits as above, giving (0001, 0010, 0111).
 
To encode a number such as 127, then,for one simply encodesexample, each of the decimal digits asis encoded using the bit pattern shown above, givingthat is: (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: either one can simply ignore the extra four bits of each byte, usually filling them with zero bits or one bits (as in [[EBCDIC]]); or one can store two digits per byte, called "packed" BCD (packed BCD also usually ends with a sign digit, for which the preferred values are 1100 for + and 1101 for -). Thus the number 127 would be represented as (11110001, 11110010, 11110111) in EBCDIC or (00010010, 01111100) in packed BCD.
 
Since most computers store data in eight-bit [[byte]]s, there are two common ways of storing four-bit BCD digits in those bytes: either one can simply ignore the extra four bits of each byte, usually filling them with either zero bits or one bits (as in [[EBCDIC]]); or one can store two digits per byte, called "packed" BCD (packed BCD numbers also usually endsend with a sign 'digit', for which the preferred values are 1100 for + and 1101 for -). Thus the number 127 would be represented as (11110001, 11110010, 11110111) in EBCDIC or (00010010, 01111100) in packed BCD.
While BCD is wasteful (about 1/6 of the available memory is wasted, even in packed BCD), it has a direct correspondence to the [[ASCII]] character set if the BCD number is prepended or OR'd with 00110000 (decimal 48), and large numbers can easily be displayed on 7-element displays by splitting up the [[Integral data type|nybbles]] and sending each to a different character (the individual characters often have the wiring to display the correct figures). 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).
 
While BCD is wasteful (about 1/6 of the available memory is wasted, even in packed BCD), it has a direct correspondence to the [[ASCII]] character set if the BCD number is prepended with 0011 or ORed with 00110000 (decimal 48), and similarly maps to EBCDIC characters if the BCD code is prefixed with 1111.
 
While BCD is wasteful (about 1/6 of the available memory is wastedFurther, even in packed BCD), it has a direct correspondence to the [[ASCII]] character set if the BCD number is prepended or OR'd with 00110000 (decimal 48), and large numbers can easily be displayed on 7-element displays by splitting up the [[Integral data type|nybbles]] and sending each to a different character (the individual characters often have the wiring to display the correct figures). 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==