BINARY CODES
- In digital logic circuits, numbers, letters or symbols are represented by a combination of binary digits. This is called
digital coding or representation using binary codes.
-Codes that represent numbers are called numeric codes while those that represent both numbers and letters or
symbols are called alphanumeric codes.
- Reasons for using binary codes:
(a) Security i.e. coding information so that others may not be able to read the message if it is intercepted.
(b) To enable efficient processing of information i.e. information is represented using fewer bits.
(c) To facilitate certain operations in data processing e.g. arithmetic operations.
(d) Using code simplifies and reduces the circuitry required to process the information. By limiting the switching
circuitry, reliability of the digital system is increased.
(e) Error detection or correction i.e. codes enable the computers to determine whether the information that was
coded and transmitted is received correctly and, if there is an error, to correct it.
-Some of the most commonly used codes in computing are:
BCD
Excess-3
Gray code
ASCII
BCD (Binary Coded Decimal) Code
- It is a numeric code in which each decimal digit is represented by a group of four binary bits.
- Since the right-to-left weighting of the 4-bit positions is 8-4-2-1, it is also called an 8421 code.
- Any decimal number can be expressed in BCD code by replacing each decimal digit by the appropriate 4-bit
combination.
- Conversely, a BCD number can be easily converted into a decimal number by grouping the coded number into
groups of four bits (starting with LSB) and then writing down the decimal digit represented by each four- bit group.
Table showing BCD codes for some decimal numbers
Decimal BCD
0 0000
6 0110
7 0111
8 1000
9 1001
26 0010 0110
673 0110 0111 0011
1
i
ng
Ba
Worked examples
1) Write the decimal number 369 in BCD code
Sol
3 6 9
0011 0110 1001 hence 001101101001
2) Find the equivalent decimal value for the BCD code number 0001010001110101
Sol
0001 0100 0111 0101
1 4 7 5 hence 147510
3) Decode the following 8421 BCD numbers:
(i) 0101
(ii) 0111
Sol
0101 = 510
0111 = 710
Exercise
1) Convert the following binary numbers into their equivalent hexadecimal numbers:
(i) 1101 0111
(ii) 1010 0110
2) Find the decimal values for the BCD-coded numbers.
(i) 0110 1000
(ii) 0111 0100 1001
BCD Addition
Either packed or unpacked BCD numbers can be summed. BCD addition follows the same rules as binary addition.
However, if the addition produces a carry and/or creates an invalid BCD number, an adjustment is required to
correct the sum.
2
i
ng
Ba
3
Ba
ng
i
4
Ba
ng
i
BCD Subtraction
Either packed or unpacked BCD numbers can be subtracted. BCD subtraction follows the same rules as binary
subtraction. However, if the subtraction causes a borrow and/or creates an invalid BCD number, an adjustment is
required to correct the answer. The correction method is to subtract 6 from the difference in any digit position that
has caused an error.
For example,
37 - 12 = 25 65 - 19 = 46 41 - 18 = 23
0011 0111 = 37 0110 0101 = 65 0100 0001 = 41
- 0001 0010 = 12 - 0001 1001 = 19 - 0001 1000 = 18
0010 0101 = 25 0100 1100 = 4? (invalid) 0010 1001 = 29 (error)
0100 1100 = 4? (invalid) 0010 1001 = 29 (error)
- 0000 0110 = 6 (adjustment) - 0000 0110 = 6 (adjustment)
0100 0110 = 46 0010 0011 = 23
5
i
ng
Ba
Exercise
1. Perform the following BCD additions:
(a) 23+20
(b) 67+33
(c) 1001+0100
2. Write the decimal equivalent for (110001)BCD
3. Carry out BCD subtraction for (68)-(61)
4. Which of the following is not an invalid BCD code?
(a) 1011
(b) 1010
(c) 1001
(d) 1100
5. Convert 000110000111 BCD to decimal
6. Explain why BCD might be a useful way to represent numbers.
6
i
ng
Ba