Binary Codes

advertisement
Binary Codes
The usual way of expressing a decimal number in terms of a binary number is
known as pure binary coding and is discussed in the Number Systems section. A
number of other techniques can be used to represent a decimal number. These are
summarised below.
8421 BCD Code
In the 8421 Binary Coded Decimal (BCD) representation each decimal digit is
converted to its 4-bit pure binary equivalent.
For example: 57dec = 0101 0111bcd
Addition is analogous to decimal addition with normal binary addition taking place
from right to left. For example,
6 0110 BCD for 6
42
0100 0010 BCD for 42
+3 0011 BCD for 3
+27
0010 0111 BCD for 27
____
1001 BCD for 9
__________
0110 1001 BCD for 69
Where the result of any addition exceeds 9(1001) then six (0110) must be added to
the sum to account for the six invalid BCD codes that are available with a 4-bit
number. This is illustrated in the example below
8
1001
BCD for 8
+7
0111
BCD for 7
_____
1111 exceeds 9 (1001) so
0110
add six (0110)
__________
0001 0101
BCD for 15
Note that in the last example the 1 that carried forward from the first group of 4 bits
has made a new 4-bit number and so represents the "1" in "15".
In the examples above the BCD numbers are split at every 4-bit boundary to make
reading them easier. This is not necessary when writing a BCD number down.
This coding is an example of a binary coded (each decimal number maps to four
bits) weighted (each bit represents a number, 1, 2, 4, etc.) code.
4221 BCD Code
The 4221 BCD code is another binary coded decimal code where each bit is
weighted by 4, 2, 2 and 1 respectively. Unlike BCD coding there are no invalid
representations. The decimal numbers 0 to 9 have the following 4221 equivalents
Decimal 4221 1's complement
0 0000
1111
1 0001
1110
2 0010
1101
3 0011
1100
4 1000
0111
5 0111
1000
6 1100
0011
7 1101
0010
8 1110
0001
9 1111
0000
the 1's complement of a 4221 representation is important in decimal arithmetic. In
forming the code remember the following rules



Below decimal 5 use the right-most bit representing 2 first
Above decimal 5 use the left-most bit representing 2 first
Decimal 5 = 2+2+1 and not 4+1
Download