Electronics · Ch 10 — Digital Electronics
Digital codes
Digital codes
Computers and electronic devices need a systematic, precise way to represent information so that every character, letter, digit and symbol is unique and distinguishable. Analog data is therefore processed into digital data that is represented, stored and transmitted as groups of binary bits. A digital code is simply a rule for converting information into such groups of 0s and 1s.
Codes are broadly of three kinds: a binary (digital) code is a group of bits using only 0 and 1; a numeric code represents numbers; and an alphanumeric code represents letters, characters and numerals. Numeric codes are further classified as weighted codes, which obey the positional-weight principle (each bit position carries a fixed weight, e.g. 8-4-2-1, 2-4-2-1, 5-4-2-1), and non-weighted codes, which do not (e.g. Excess-3 and Gray code).
BCD (8-4-2-1) code
In Binary Coded Decimal (BCD) each decimal digit is represented by its own group of four bits. The most common is the 8-4-2-1 BCD code, where the four bit positions carry weights 8, 4, 2 and 1 from left to right (table 10.2.1). Because four bits can form sixteen combinations but only ten are needed, six combinations (1010 to 1111) are invalid in BCD. BCD is less efficient than pure binary but is easy to convert to and from decimal, so it is used in calculators, seven-segment displays and digital watches. For a multi-digit number each decimal digit is coded separately — for example, decimal 42 becomes 0100 0010.
Self-complementing codes and 9's complement
A code is self-complementing when the code of the 9's-complement of a digit is obtained simply by interchanging all the 1s and 0s (taking the 1's complement) of that digit's code. The 9's complement of a decimal digit is found by subtracting it from 9 (table 10.2.2); for a multi-digit number each digit is complemented separately — e.g. the 9's complement of 7825 is 2174.
Excess-3 (XS-3) code
The Excess-3 code is a non-weighted, self-complementing code formed by adding 0011 (binary) — that is, 3 (decimal) — to each 8-4-2-1 BCD code word (table 10.2.3). Its self-complementing property makes it convenient for arithmetic subtraction. Six of its sixteen combinations (0000, 0001, 0010, 1101, 1110, 1111) are invalid.
2-4-2-1 code
The 2-4-2-1 code is a weighted, self-complementing 4-bit code whose bit weights from left to right are 2, 4, 2 and 1 (table 10.2.4). Because two positions share the weight 2, some digits could be coded in more than one way; to preserve the self-complementing property the standard coding is used and six combinations (0101, 0110, 0111, 1000, 1001, 1010) must not be used. It is widely used in arithmetic operations.
Gray code
The Gray code is a non-weighted unit-distance (minimum-change) code: successive numbers differ by only one bit (table 10.2.5). Because it is non-weighted it cannot be used directly for arithmetic, but the single-bit change makes it valuable in shaft-position encoders, analog-to-digital conversion and reducing errors in data transmission.
- Binary → Gray: copy the MSB unchanged, then each remaining Gray bit is the XOR of two adjacent binary bits. Figure 10.2.1 realizes this with three XOR gates.
- Gray → Binary: copy the MSB unchanged, then each binary bit is the XOR of the previous binary bit with the current Gray bit. Figure 10.2.2 realizes this with three XOR gates.
Alphanumeric codes
Alphanumeric codes represent digits, alphabets and special characters (at least 10 digits and 26 letters). The three common ones are ASCII, EBCDIC and the five-bit Baudot code. …
A rule for converting information into groups of binary bits (0s and 1s) so that each character, digit or symbol is uniquely represented, stored and transmitted. A binary/digital code uses only 0 and 1; a numeric code represents numbers; an alphanumeric cod …
A weighted code obeys the positional-weight principle — each bit position carries a fixed weight (e.g. 8-4-2-1, 2-4-2-1, 5-4-2-1). A non-weighted code does not follow any positional weig …
Column weights 8, 4, 2, 1.
| Decimal | 8 | 4 | 2 | 1 |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 1 | 1 |
| 4 | 0 | 1 | 0 | 0 |
| 5 | 0 | 1 | 0 | 1 |
| 6 | 0 | 1 | 1 | 0 |
| 7 | 0 | 1 | 1 | 1 |
| 8 | 1 | 0 | 0 | 0 |
| 9 | 1 | 0 | 0 | 1 |
A code in which each decimal digit is represented by its own separate group of four bits. The common form is 8-4-2-1 BCD. It is easy to convert to and from decimal but less efficient than pure binary; used in calculators, sev …
A code in which the code word of the 9's complement of a decimal digit is obtained by simply interchanging all the 1s and 0s (the 1's complement) of that digit's code word. Excess-3 and 2-4 …
The 9's complement of a digit is 9 minus that digit.
| Decimal | 9's complement |
|---|---|
| 0 | 9 |
| 1 | 8 |
| 2 | 7 |
| 3 | 6 |
| 4 | 5 |
| 5 | 4 |
| 6 | 3 |
| 7 | 2 |
Excess-3 = 8-4-2-1 BCD + 0011.
| Decimal | BCD (8421) | Excess-3 |
|---|---|---|
| 0 | 0000 | 0011 |
| 1 | 0001 | 0100 |
| 2 | 0010 | 0101 |
| 3 | 0011 | 0110 |
| 4 | 0100 | 0111 |
| 5 | 0101 | 1000 |
| 6 | 0110 | 1001 |
| 7 | 0111 | 1010 |
| 8 | 1000 | 1011 |
| 9 | 1001 | 1100 |
Excess-3 code = 8-4-2-1 BCD + 0011 (binary) = decimal digit + 3. Add 0011 to each BCD nibble to obtain its Excess-3 code word. Because 3 is added to every digit, Excess-3 is non-weighted and self-complementing: e.g. decimal 5 → BCD 0101 → add 0011 → Excess-3 1000. This shift is …
Column weights 2, 4, 2, 1 (left to right).
| Decimal | 2 | 4 | 2 | 1 |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 2 | 0 | 0 | 1 | 0 |
| 3 | 0 | 0 | 1 | 1 |
| 4 | 0 | 1 | 0 | 0 |
| 5 | 1 | 0 | 1 | 1 |
| 6 | 1 | 1 | 0 | 0 |
| 7 | 1 | 1 | 0 | 1 |
| 8 | 1 | 1 | 1 | 0 |
| 9 | 1 | 1 | 1 | 1 |
Check: e.g. 5 = 1011 = 2+0+2+1 and 9 = 1111 = 2+4+2+1. The six combinations 0101, 0110, 0111, 1000, 1001, 1010 must not be used. …
Successive Gray codes differ by exactly one bit.
| Decimal | BCD | Gray |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
A non-weighted, unit-distance (minimum-change) code in which successive values differ by only one bit. It cannot be used for arithmetic but is used in shaft-position encoders, analog-to-digital conversion and …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
Figure 10.2.1: the four binary bits enter on the left; the MSB passes straight through to the Gray output, and each remaining Gray bit is produced by an XOR gate combining two adjacent binary bits. Illustra …
Drawn by us to help you understand the concept clearly, and verified to make sure it's accurate. For exams, practice from your textbook's own diagram.
Figure 10.2.2: the Gray bits enter on the left; the MSB passes straight through to the binary MSB, and each further XOR combines the running binary result with the next Gray bit. Illustrated …
Binary to Gray: the MSB is copied, then each Gray bit (XOR of adjacent binary bits). Gray to binary: the MSB is copied, then each binary bit (XOR of the previous …
Codes that represent digits, alphabets and special characters (at least 10 digits and 26 letters). The three common ones are ASCII (7-bit, 128 groups), EBCDIC (8-bit, 256 character …
A sample of the 7-bit ASCII code.
| Character | 7-bit binary | Octal | Hex | Decimal |
|---|---|---|---|---|
| line feed | 000 1010 | 012 | 0A | 10 |
| return | 000 1101 | 015 | 0D | 13 |
| blank (space) | 010 0000 | 040 | 20 | 32 |
| $ | 010 0100 | 044 | 24 | 36 |
| ( | 010 1000 | 050 | 28 | 40 |
| ) | 010 1001 | 051 | 29 | 41 |
| * | 010 1010 | 052 | 2A | 42 |
| + | 010 1011 | 053 | 2B | 43 |
| , | 010 1100 | 054 | 2C | 44 |
| - | 010 1101 | 055 | 2D | 45 |
| / | 010 1111 | 057 | 2F | 47 |
| 0 | 011 0000 | 060 | 30 | 48 |
| 9 | 011 1001 | 071 | 39 | 57 |
| = | 011 1101 | 075 | 3D | 61 |
| A | 100 0001 | 101 | 41 | 65 |
| Z | 101 1010 | 132 | 5A | 90 |
| a | 110 0001 | 141 | 61 | 97 |
| z | 111 1010 | 172 | 7A | 122 |
Each character is split into a zone part and a digit part. EBCDIC zones: A-I = 1100, J-R = 1101, S-Z = 1110, digits = 1111.
| Character | BCD zone-digit (6-bit) | EBCDIC zone-digit (8-bit) |
|---|---|---|
| A | 11 0001 | 1100 0001 |
| C | 11 0011 | 1100 0011 |
| P | 10 0111 | 1101 0111 |
| U | 01 0100 | 1110 0100 |
| Z | 01 1001 | 1110 1001 |
| 1 | 00 0001 | 1111 0001 |
| 9 | 00 1001 | 1111 1001 |