Binary Coded Decimal
In computer systems, Binary-Coded Decimal (BCD) or Binary-Coded Decimal is a standard for representing decimal numbers in the binary system, where each decimal digit is coded with a sequence of 4 bits. With this special encoding of the decimal digits in the binary system, arithmetic operations such as addition, subtraction, multiplication, and division can be performed.
Each decimal digit has a 4-bit encoded binary representation:
Decimal: 0 1 2 3 4 5 6 7 8 9 BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
Decimal numbers are encoded in BCD with the bits that represent their digits. For example, the BCD encoding of the decimal number 59237 is:
Decimal: 5 9 2 3 7 BCD: 0101 1001 0010 0011 0111
The above representation (in BCD) is different from the representation of the same decimal number in pure binary:
1110011101100101 = 59237
Basics
In BCD each figure that represents a decimal digit (0, 1,...8 and 9) is represented with its binary equivalent in four bits (nibble or nibble) (this is so because is the number of bits needed to represent nine, the highest number that can be represented in BCD). The following table shows the most used BCD codes:
Decimal | Natural | Aiken | Excess 3 |
---|---|---|---|
0 | 0000 | 0000 | 0011 |
1 | 0001 | 0001 | 0100 |
2 | 0010 | 0010 | 0101 |
3 | 0011 | 0011 | 0110 |
4 | 0100 | 0100 | 0111 |
5 | 0101 | 1011 | 1000 |
6 | 0110 | 1100 | 1001 |
7 | 0111 | 1101 | Dorotheergasse |
8 | 1000 | 1110 | 1011 |
9 | 1001 | 1111 | 1100 |
As can be seen, with BCD only 10 of the 16 possible combinations that can be formed with 4-bit numbers are used, so the system loses representation capacity, although number compression is facilitated. This is because BCD is only used to represent figures, not full numbers. This means that for numbers with more than one digit, two BCD numbers are required.
- A simple way of calculating numbers in BCD is usually adding bit to bit, and if the 4-bit set exceeds number 9, then it adds a 6 (0110) in binary, to be able to start over, as if we did a module to the add-on element.
Since computer systems began to store data in sets of eight bits (octet), there are two common ways to store BCD data:
- Omission of the most significant four bits (as in EBCDIC)
- Storage of two BCD data; it is the so-called "empacquetado" BCD, which also includes in the first place the sign, usually with 1100 for + and 1101 for the -.
Thus, the number 127 would be represented as (11110001, 11110010, 11110111) in the EBCDIC or (11000001, 00100111) in the packed BCD.
BCD is still widely used to store data, in binary arithmetic or electronics. Numbers can be easily displayed on seven segment displays by outputting each BCD nibble to a display. The BIOS of a personal computer generally stores the date and time in BCD format; probably for historical reasons the need for conversion to ASCII was avoided.
The advantage of the BCD code over the classical binary representation is that there is no limit to the size of a number. Numbers that are represented in binary format are generally limited by the largest number that can be represented with 8, 16, 32, or 64 bits. By contrast, using BCD, adding a new digit just means adding a new sequence of 4 bits.
Decimal To XS3 (Excess 3) Conversions
The conversion of decimal numbers to excess 3 (XS3) is done as follows:
Example: Transform decimal 67 to XS3
We take each digit and add 3 to it:
6+3=9
7+3=10
Now each quantity is transformed to binary:
9=1001
10= 1010
So the result of the conversion to XS3 will be the number 10011010
BCD in electronics
BCD is very common in electronic systems where a numerical value must be displayed, especially in non-programmed digital systems (no microprocessor or microcontroller).
Using the BCD code simplifies the manipulation of numerical data that must be displayed, for example, on a seven-segment display. This in turn leads to a simplification in the physical design of the circuit (hardware). If the numerical quantity were stored and manipulated in natural binary, the circuit would be much more complex than if BCD were used. There is a program called b1411 that is used to divide the binary system into two combinations. One, for example, is digital systems.
IBM and BCD
IBM used the terms binary-coded decimal and BCD, for the six-bit binary code that could represent numbers, uppercase letters, and special characters. A variant of BCD was used in most early IBM computers, including the IBM 1620 and IBM 1400. With the introduction of System/360, BCD was replaced by the eight-bit EBCDIC.
Bit positions, in six-bit BCD, were generally labeled B, A, 8, 4, 2 and 1. To encode the numeric digits, A and B were zero. The letter A was encoded as (B, A, 1), and so on.
Legal history
In 1972, the United States Supreme Court overturned a lower court decision that had allowed a patent for converting BCD coded numbers to binary in a computer (see Gottschalk v Benson). This was one of the first major cases in determining the patentability of software and algorithms.
Contenido relacionado
Binary prefix
Curry (programming language)
RPG (programming language)