All Topics  
Binary-coded decimal

 

   Email Print
   Bookmark   Link






 

Binary-coded decimal



 
 
In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
 and electronic
Electronics

Electronics refers to the flow of charge through nonmetal electrical conductor , whereas electrical refers to the flow of charge through metal electrical conductor....
 systems, binary-coded decimal (BCD) (sometimes called natural binary-coded decimal, NBCD) 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—it occupies more space than a pure binary representation.

In BCD, a digit
Numerical digit

In mathematics and computer science, a digit is a symbol used in numerals , to represent numbers, in Positional notation numeral systems. The name "digit" comes from the fact that the 10 digits of the hands correspond to the 10 symbols of the common base 10 number system, i.e....
 is usually represented by four bit
Bit

A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory....
s which, in general, represent the values/digits/characters 0–9.






Discussion
Ask a question about 'Binary-coded decimal'
Start a new discussion about 'Binary-coded decimal'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
 and electronic
Electronics

Electronics refers to the flow of charge through nonmetal electrical conductor , whereas electrical refers to the flow of charge through metal electrical conductor....
 systems, binary-coded decimal (BCD) (sometimes called natural binary-coded decimal, NBCD) 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—it occupies more space than a pure binary representation.

In BCD, a digit
Numerical digit

In mathematics and computer science, a digit is a symbol used in numerals , to represent numbers, in Positional notation numeral systems. The name "digit" comes from the fact that the 10 digits of the hands correspond to the 10 symbols of the common base 10 number system, i.e....
 is usually represented by four bit
Bit

A bit is a binary numeral system numerical digit, taking a value of either 0 or 1. Binary digits are a basic unit of information Computer data storage and transmission in digital computing and digital information theory....
s which, in general, represent the values/digits/characters 0–9. Other bit combinations are sometimes used for a sign
Negative and non-negative numbers

A negative number is a real number that is inequality 0 , such as -3. A positive number is a real number that is greater than zero, such as 2....
 or other indications.

Although BCD is not as widely used as it once was, decimal fixed-point and floating-point are still important and continue to be used in financial, commercial, and industrial computing. Modern decimal floating-point representations use base-10 exponents, but not BCD encodings. Current hardware implementations, however, convert the compressed decimal
Densely Packed Decimal

Densely packed decimal is a system of Binary coding encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....
 encodings to BCD internally before carrying out computations. Software implementations use BCD or some other 10n base, depending on the operation.

Basics


To BCD-encode a decimal number using the common encoding, each decimal digit is stored in a four-bit nibble
Nibble

A nibble is the computing term for a four-bit aggregation, or half an octet . As a nibble contains 4 bits, there are sixteen possible values, so a nibble corresponds to a single hexadecimal digit ....
.

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 byte
Byte

A byte is a basic unit of measurement of Computer storage in computer science. In many computer architectures it is a Byte addressing memory address space....
s, there are two common ways of storing four-bit BCD digits in those bytes:
  • each digit is stored in one nibble of a byte, with the other nibble being set to all zeros, all ones (as in the EBCDIC
    EBCDIC

    Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used on IBM mainframe operating systems such as z/OS, OS/390, VM and VSE , as well as IBM midrange computer operating systems such as OS/400 and i5/OS ....
     code), or to 0011 (as in the ASCII
    ASCII

    American Standard Code for Information Interchange , is a coding standard that can be used for interchanging information, if the information is expressed mainly by the written form of English words....
     code)
  • two digits are stored in each byte.


Unlike binary-encoded numbers, BCD-encoded numbers can easily be displayed by mapping each of the nibbles to a different character. Converting a binary-encoded number to decimal for display is much harder, as this generally involves integer multiplication or divide operations. BCD also avoids problems where fractions that can be represented exactly in decimal cannot be in binary (eg one-tenth).

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 utilizing 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 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). All of the upper bytes of a multi-byte word plus the upper four bits (nibble
Nibble

A nibble is the computing term for a four-bit aggregation, or half an octet . As a nibble contains 4 bits, there are sixteen possible values, so a nibble corresponds to a single hexadecimal digit ....
) of the lowest byte are used to store decimal integers. The lower four bits of the lowest byte are used as the sign flag. As an example, a 32 bit word contains 4 bytes or 8 nibbles. Packed BCD uses the upper 7 nibbles to store the integers of a decimal value and uses the lowest nibble to indicate the sign of those integers.

Standard sign values are 1100 (Ch
Hexadecimal

In mathematics and computer science, hexadecimal is a numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 09 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen....
) for positive (+) and 1101 (Dh) for negative (-). Other allowed signs are 1010 (Ah) and 1110 (Eh) for positive and 1011 (Bh) for negative. Some implementations also provide unsigned BCD values with a sign nibble of 1111 (Fh). In packed BCD, the number 127 is represented by "0001 0010 0111 1100" (127Ch) and -127 is represented by "0001 0010 0111 1101 (127Dh).

No matter how many bytes wide a word is, there are always an even number of nibbles because each byte has two of them. Therefore, a word of n bytes can contain up to (2n)-1 decimal digits, which is always an odd number of digits. A decimal number with d digits requires ˝(d+1) bytes of storage space.

For example, a four-byte (32bit) 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:

0001 0010 0011 0100 0101 0110 0111 1101 1 2 3 4 5 6 7 -

(Note that, like character strings, the first byte of the packed decimal – with the most significant two digits – is usually stored in the lowest address in memory, independent of the endianness
Endianness

In computing, endianness is the byte ordering used to represent some kind of data. Typical cases are the order in which integer values are stored as bytes in computer memory and the transmission order over a network or other medium....
 of the machine).

In contrast, a four-byte binary two's complement
Two's complement

The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of two .A two's-complement system or two's-complement arithmetic is a system in which negative numbers are represented by the two's complement of the absolute value; this system is the most common Signed number r...
 integer can represent values from −2,147,483,648 to +2,147,483,647.

While packed BCD does not make optimal use of storage (about 1/6 of the memory used is wasted), conversion to ASCII
ASCII

American Standard Code for Information Interchange , is a coding standard that can be used for interchanging information, if the information is expressed mainly by the written form of English words....
, EBCDIC
EBCDIC

Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used on IBM mainframe operating systems such as z/OS, OS/390, VM and VSE , as well as IBM midrange computer operating systems such as OS/400 and i5/OS ....
, or the various encodings of Unicode
Unicode

Unicode is a computing industry standard allowing computers to consistently represent and manipulate Character expressed in most of the world's writing systems....
 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. Denser packings of BCD
BCD

BCD may refer to:* Bad Conduct Discharge, a form of discharge from US military service* Bachelor of Community Design, a three year university degree offered at Dalhousie University...
 exist which avoid the storage penalty and also need no arithmetic operations for common conversions.

Fixed-point packed decimal


Fixed-point
Fixed-point arithmetic

In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the radix point . Fixed-point number representation can be compared to the more complicated floating point number representation....
 decimal numbers are supported by some programming languages (such as COBOL
COBOL

COBOL is one of the oldest programming languages still in active use. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
 and PL/I
PL/I

PL/I is an imperative programming computer programming programming language designed for scientific, engineering, and business applications. It is one of the most feature-rich programming languages and one of the very first in the highly-feature-rich category....
), 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. 12 34 56 7C 12 34.56 7+

Higher-density encodings


If a decimal digit requires four bits, then three decimal digits require 12 bits. However, since 210 (1,024) is greater than 103 (1,000), if three decimal digits are encoded together, only 10 bits are needed. Two such encodings are Chen-Ho encoding
Chen-Ho encoding

Chen-Ho encoding is an alternate system of Binary numeral system encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....
 and Densely Packed Decimal
Densely Packed Decimal

Densely packed decimal is a system of Binary coding encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....
. 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 implementations (notably IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 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
EBCDIC

Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used on IBM mainframe operating systems such as z/OS, OS/390, VM and VSE , as well as IBM midrange computer operating systems such as OS/400 and i5/OS ....
 codes for the characters "0" through "9". Similarly, ASCII
ASCII

American Standard Code for Information Interchange , is a coding standard that can be used for interchanging information, if the information is expressed mainly by the written form of English words....
 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: F1 F2 D3 1 2 -3

EBCDIC zoned decimal conversion table


BCD DigitEBCDIC CharacterHexadecimal
0+  (*)^  (*) D0B0 
1−J  D1B1 
2−K  D2B2 
3−L  D3B3 
4−M  D4B4 
5−N  D5B5 
6−O  D6B6 
7−P  D7B7 
8−Q  D8B8 
9−R  D9B9 


(*) Note: These characters vary depending on the local character code page
Code page

Code page is the traditional International Business Machines term used to map a specific set of characters to numerical code point values . This is slightly different in meaning than the related terms character encoding and character set....
.


Fixed-point zoned decimal


Some languages (such as COBOL
COBOL

COBOL is one of the oldest programming languages still in active use. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
 and PL/I
PL/I

PL/I is an imperative programming computer programming programming language designed for scientific, engineering, and business applications. It is one of the most feature-rich programming languages and one of the very first in the highly-feature-rich category....
) 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

IBM and BCD

IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 used the terms binary-coded decimal and BCD for 6-bit alphameric
Alphanumeric

Alphanumeric is a portmanteau of alphabetic and numeric and is used to describe the collection of Latin alphabet and Arabic numerals used by much of western society....
 codes that represented numbers, upper-case letters and special characters. Some variation of BCD alphamerics was used in most early IBM computers, including the IBM 1620
IBM 1620

The IBM 1620 was announced by International Business Machines 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....
, IBM 1400 series
IBM 1400 series

The IBM 1400 series were second generation 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....
, and non-Decimal Architecture
IBM 700/7000 series

The IBM 700/7000 series was a series of large scale computer systems made by International Business Machines through the 1950s and early 1960s....
 members of the IBM 700/7000 series
IBM 700/7000 series

The IBM 700/7000 series was a series of large scale computer systems made by International Business Machines through the 1950s and early 1960s....
.

Bit positions in BCD alphamerics 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 IBM 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 6-bit BCD codes.

In the Decimal Architecture IBM 7070
IBM 7070

IBM 7070 was a decimal architecture intermediate data processing system that was introduced by IBM in June 1960. It was part of the IBM 700/7000 series, and was based on discrete transistors rather than the vacuum tubes of the 1950s....
, IBM 7072, and IBM 7074 alphamerics were encoded using digit pairs (using two-out-of-five code
Two-out-of-five code

In telecommunication, a two-out-of-five code is an m of n codes that provides exactly ten possible combinations, and thus is popular for representing decimal digits using five bits....
 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.

With the introduction of System/360
System/360

The IBM System/360 is a mainframe computer system family announced by IBM on April 7, 1964. It was the first family of computers making a clear distinction between computer architecture and implementation, allowing IBM to release a suite of compatible designs at different price points....
, IBM expanded 6-bit BCD alphamerics to 8-bit EBCDIC
EBCDIC

Extended Binary Coded Decimal Interchange Code is an 8-bit character encoding used on IBM mainframe operating systems such as z/OS, OS/390, VM and VSE , as well as IBM midrange computer operating systems such as OS/400 and i5/OS ....
, allowing the addition of many more characters (e.g., lowercase letters). A variable length Packed BCD numeric data type was also implemented.

Today, BCD data is still heavily used in IBM processors and databases, such as IBM DB2
IBM DB2

DB2 is one of IBM's families of relational database management system software products within IBM's broader IBM Information Management Software line....
, mainframes, and Power6
POWER6

The POWER6 microprocessor is IBM's follow-on to the POWER5. It is part of the eCLipz, said to have a goal of converging IBM's server hardware where practical ....
. 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 within hardware registers and processing units, and in software.

Addition with BCD


It is possible to perform addition
Addition

Addition is the mathematics process of putting things together. The plus sign "+" means that numbers are added together. For example, in the picture on the right, there are 3 + 2 apples?meaning three apples and two other apples?which is the same as five apples, since 3 + 2 = 5....
 in BCD by first adding in binary, and then converting to BCD afterwards. Conversion of the simple sum of two digits can be done by adding 6 (that is, 16 – 10) when the result has a value greater than 9. For example:

1001 + 1000 = 10001 = 0001 0001 9 + 8 = 17 = 1 1

In BCD, there cannot exist a value greater than 9 (1001) per nibble
Nibble

A nibble is the computing term for a four-bit aggregation, or half an octet . As a nibble contains 4 bits, there are sixteen possible values, so a nibble corresponds to a single hexadecimal digit ....
. To correct this, 6 (0110) is added to that sum to get the correct first two digits:

0001 0001 + 0000 0110 = 0001 0111 1 1 + 0 6 = 1 7

which gives two nibbles, 0001 and 0111, which correspond to the digits "1" and "7". This yields "17" in BCD, which is the correct result. This technique can be extended to adding multiple digits, by adding in groups from right to left, propagating the second digit as a carry, always comparing the 5-bit result of each digit-pair sum to 9.

Subtraction with BCD


Subtraction is done by adding the ten's complement of the subtrahend. To represent the sign of a number in BCD, the number 0000 is used to represent a positive
Positive

Positive is a property of positivity and may refer to:...
 number, and 1001 is used to represent a negative
Negative

The term negative refers to a property of negativity and may refer to:...
 number. The remaining 14 combinations are invalid signs. To illustrate signed BCD subtraction, consider the following problem: 357 - 432.

In signed BCD, 357 is 0000 0011 0101 0111. The ten's complement of 432 can be obtained by taking the nine's complement of 432, and then adding one. So, 999 - 432 = 567, and 567 + 1 = 568. By preceding 568 in BCD by the negative sign code, the number -432 can be represented. So, -432 in signed BCD is 1001 0101 0110 1000.

Now that both numbers are represented in signed BCD, they can be added together:

0000 0011 0101 0111 + 1001 0101 0110 1000 = 1001 1000 1011 1111 0 3 5 7 + 9 5 6 8 = 9 8 11 15

Since BCD is a form of decimal representation, several digits sums above are invalid. In the event that an invalid entry (any BCD digit greater than 1001) exists, simply add 6 to generate a carry bit and cause the sum to become a valid entry. The reason for adding 6 is because there are 16 possible 4-bit BCD values (since 24 = 16), but only 10 values are valid (0000 through 1001). So, adding 6 to the invalid entries results in the following:

1001 1000 1011 1111 + 0000 0000 0110 0110 = 1001 1001 0010 0101 9 8 11 15 0 0 6 6 9 9 2 5

So, the result of the subtraction is 1001 1001 0010 0101 (-925). To check the answer, note that the first bit is the sign bit, which is negative. This seems to be correct, since 357 - 432 should result in a negative number. To check the rest of the digits, represent them in decimal. 1001 0010 0101 is 925. The ten's complement of 935 is 999 - 925 = 074 + 1 = 75, so the calculated answer is -75. To check, perform standard subtraction to verify that 357 - 432 is -75.

Note that in the event that there are a different number of nibbles being added together (such as 1053 - 122), the number with the fewest number of digits must first be padded with zeros before taking the ten's complement or subtracting. So, with 1053 - 122, 122 would have to first be represented as 0122, and the ten's complement of 0122 would have to be calculated.

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', etc., indicates the weight of each bit shown; note that in the 5th column two of the weights are negative. Both ASCII and EBCDIC character codes for the digits are examples of zoned BCD, and are also shown in the table.

The following table represents decimal
Decimal

The decimal numeral system has 10 as its Base . It is the most widely used numeral system....
 digits from 0 to 9 in various BCD systems:

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 ). This was an important case in determining the patentability of software and algorithms.

Comparison with pure binary


Advantages

  • 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.
  • 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)
  • Rounding
    Rounding

    Rounding involves reducing the number of significant digits in a number. The result of rounding is a "shorter" number having fewer non-zero digits yet similar in magnitude....
     at a decimal digit boundary is simpler. Addition and subtraction in decimal does not require rounding.
  • 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
    Seven-segment display

    A seven-segment display , less commonly known as a seven-segment indicator, is a form of electronic display device for displaying decimal numeral system that is an alternative to the more complex dot-matrix displays....
    ) is a simple per-digit mapping, and can be done in linear (O(n)) time. Conversion from pure binary
    Binary numeral system

    The binary numeral system, or notation with a radix of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers....
     involves relatively complex logic that spans digits, and for large numbers no linear-time conversion algorithm is known (see Binary numeral system
    Binary numeral system

    The binary numeral system, or notation with a radix of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers....
    ).


Disadvantages

  • Some operations are more complex to implement. Adder
    Adder (electronics)

    In electronics, an adder or summer is a digital circuit that performs addition of numbers.In modern computers adders reside in the arithmetic logic unit where other operations are performed....
    s 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
    Binary numeral system

    The binary numeral system, or notation with a radix of 2. Owing to its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by all modern computers....
    , 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% more space than a binary encoding. When packed so that three digits are encoded in ten bits, the storage overhead is reduced to about 0.34%, 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.
  • 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.


Applications

The BIOS
BIOS

In computing, the Basic Input/Output System , also known as the System BIOS, is a de facto standard defining a firmware interface for IBM PC Compatible computers....
 in many PCs keeps the date and time in BCD format, probably for historical reasons (it avoided the need for binary to ASCII conversion).

Representational variations

Various BCD implementations exist that employ other representations for numbers. Programmable calculator
Programmable calculator

Programmable calculators are calculators capable of being computer programming much like a computer.Since the early 1990s, most of these flexible handheld units belong to the class of graphing calculators....
s manufactured by Texas Instruments
Texas Instruments

Texas Instruments , better known in the electronics industry as TI, is an United States company based in Dallas, Texas, Texas, United States, renowned for developing and commercializing semiconductor and computer technology....
, Hewlett-Packard
Hewlett-Packard

The Hewlett-Packard Company , commonly referred to as HP, is a technology corporation headquartered in Palo Alto, California, United States....
, 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
Infinity

Infinity comes from the Latin infinitas or "unboundedness." It refers to several distinct concepts – usually linked to the idea of "without end" – which arise in philosophy, mathematics, and theology....
, underflow
Arithmetic underflow

Arithmetic underflow is a condition that can occur when the result of a floating-point operation would be smaller in magnitude than the smallest quantity representable....
/overflow
Arithmetic overflow

The term arithmetic overflow or simply overflow has the following meanings.# In a digital computer, the condition that occurs when a calculation produces a result that is greater in magnitude than what a given processor register or Computer storage location can store or represent....
, and error
Defined and undefined

In mathematics, defined and undefined are used to explain whether or not expressions have meaningful, sensible, and unambiguous values. Not all branches of mathematics come to the same conclusion....
 (a blinking display).

Alternative encodings


If error in representation and computation is the primary concern, rather than efficiency of conversion to and from display form, a scaled binary representation may be used, which stores a decimal number as a binary-encoded integer and a binary-encoded signed decimal exponent. For example, 0.2 can be represented as 2. This representation allows rapid multiplication and division, but may require multiplication by a power of 10 during addition and subtraction to align the decimals. It is particularly appropriate for applications with a fixed number of decimal places, which do not require adjustment during addition and subtraction and need not store the exponent explicitly.

Chen-Ho encoding
Chen-Ho encoding

Chen-Ho encoding is an alternate system of Binary numeral system encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....
 provides a boolean transformation for converting groups of three BCD-encoded digits to and from 10-bit values that can be efficiently encoded in hardware with only 2 or 3 gate delays. Densely Packed Decimal
Densely Packed Decimal

Densely packed decimal is a system of Binary coding encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....
 is a similar scheme that deals more efficiently and conveniently with the case where the number of digits is not a multiple of 3; this is the decimal encoding used in the IEEE 754-2008 Standard.

See also


  • Gray code
    Gray code

    |}The reflected binary code, also known as Gray code after Frank Gray , is a binary numeral system where two successive values differ in only one bit....
  • Densely packed decimal
    Densely Packed Decimal

    Densely packed decimal is a system of Binary coding encoding for decimal digits.The traditional system of binary encoding for decimal digits, known as Binary-coded decimal , uses four bits to encode each digit, resulting in significant wastage of binary data bandwidth ....


External links

  • .