Digital LogicsUnit 57 min read
Coding Systems, Conversions & Real-World Applications
Unit 5 of Digital Logics covers binary coding schemes (BCD, Excess-3, Gray, ASCII, EBCDIC), conversion techniques between codes, parity bits, Hamming codes, and practical applications in data storage, communication protocols, and error detection—with visual logic diagrams and real-world examples from Nepali tech (eSewa
TAKEAWAYS:
- BCD and weighted codes (8421, Excess-3) encode decimal digits in 4-bit binary, with Excess-3 adding 3 to each digit to simplify arithmetic.
- Non-weighted codes (Gray, ASCII) prioritize error resistance or human readability, with ASCII using 7/8 bits for text and control characters.
- Conversion circuits (e.g., BCD-to-Excess-3) use XOR gates and lookup tables derived from truth tables, visualized in K-maps for optimization.
- Error detection relies on parity bits (even/odd) and Hamming codes (single-bit correction) via syndrome calculation.
- Real-world ties: WhatsApp uses ASCII for text encoding; eSewa’s transaction IDs employ BCD for decimal compatibility; Ncell’s SMS uses Hamming codes for error-free delivery.
- Exam focus: Design truth tables, logic diagrams, and state tables for converters; explain parity/Hamming with worked examples.
1. Binary Coding Systems: Definitions and Classification
Binary codes represent decimal, alphanumeric, or special characters in binary form. They are classified into:
- Weighted codes: Each bit position has a fixed weight (e.g., 8421 BCD).
- Non-weighted codes: No fixed bit weights (e.g., Gray code, ASCII).
- Alphanumeric codes: Encode letters, digits, and symbols (e.g., ASCII, EBCDIC).
- Error-detecting/correcting codes: Add redundancy for reliability (e.g., parity, Hamming codes).
1.1 Weighted Codes: BCD and Excess-3
Binary-Coded Decimal (BCD) encodes each decimal digit (0–9) into 4 bits, using only 10 combinations (0000 to 1001). The weights are 8, 4, 2, 1 (8421 BCD).
Excess-3 code adds 3 to each decimal digit before BCD encoding (e.g., 5 → 8 → 1000). This simplifies subtraction and avoids invalid codes (1010–1111).
classDiagram
class BCD {
+Weights: 8 4 2 1
+Range: 0000 (0) to 1001 (9)
+Invalid: 1010–1111
}
class Excess3 {
+Formula: Decimal + 3 → BCD
+Range: 0011 (0) to 1110 (9)
+Advantage: No invalid codes
}
BCD --> Excess3 : "Excess-3 = BCD + 3"1.2 Non-Weighted Codes: Gray Code and ASCII
- Gray Code: Adjacent numbers differ by one bit (e.g.,
0000→0001→0011). Used in shaft encoders and error-prone transmission. - ASCII (American Standard Code for Information Interchange): 7-bit code for text (32–126) + 128 extended characters. Used in all computers and communication protocols.
| Decimal | BCD (8421) | Excess-3 | Gray Code | ASCII (Char) |
|---|---|---|---|---|
| 0 | 0000 | 0011 | 0000 | 32 (Space) |
| 1 | 0001 | 0010 | 0001 | 49 ('1') |
| 2 | 0010 | 0001 | 0011 | 65 ('A') |
| 5 | 0101 | 0110 | 0111 | 97 ('a') |
The 95 printable ASCII characters (32–126) in a grid. (Image: Shisma, CC BY-SA 4.0, via Wikimedia Commons)
2. Code Conversion: Truth Tables and Logic Circuits
Conversion between codes (e.g., BCD to Excess-3) requires:
- Truth table: List all inputs (BCD) and outputs (Excess-3).
- K-map simplification: Minimize logic gates.
- Logic diagram: Implement with gates (AND/OR/XOR).
Worked Example: BCD to Excess-3 Converter
Step 1: Truth Table
| BCD (Input) | Excess-3 (Output) |
|---|---|
| 0000 (0) | 0011 |
| 0001 (1) | 0010 |
| 0010 (2) | 0001 |
| ... | ... |
| 1001 (9) | 1110 |
Step 2: K-map for Output Bit 0 (LSB)
AB CD | 00 01 11 10
------|-----------
00 | 1 0 0 1
01 | 0 1 1 0
11 | 1 0 0 1
10 | 0 1 1 0
Groups: (00,10)(01,11) → A'C' + AC (XOR-like).
Step 3: Logic Diagram
flowchart LR
A["BCD Bit 3"] -->|"1"| AND1["AND"]
B["BCD Bit 2"] -->|"1"| AND1
C["BCD Bit 1"] -->|"0"| AND2["AND"]
D["BCD Bit 0"] -->|"0"| AND2
AND1 --> OR1["OR"]
AND2 --> OR1
OR1 --> XOR1["XOR"]
XOR1 --> E3_0["Excess-3 Bit 0"]3. Error Detection and Correction
3.1 Parity Bit
- Even parity: Number of 1s (including parity) is even.
- Odd parity: Number of 1s is odd.
Example: Transmit
1101(3 ones) with even parity →11101.
3.2 Hamming Code (Single-Bit Error Correction)
Uses redundant bits (r1, r2, r4) to locate and correct errors.
Steps:
- Assign bits to positions:
d4 d3 d2 r2 d1 r1 d0. - Calculate parity for groups:
r1 = d1 ⊕ d2 ⊕ d4r2 = d2 ⊕ d3 ⊕ d4r4 = d1 ⊕ d3 ⊕ d4
- Syndrome: Combine
r1,r2,r4to find error position.
Example: Encode 1001 (d4=1, d3=0, d2=0, d1=0).
r1 = 0 ⊕ 0 ⊕ 1 = 1r2 = 0 ⊕ 0 ⊕ 1 = 1r4 = 0 ⊕ 0 ⊕ 1 = 1Encoded:1001101(d4 d3 d2 r2 d1 r1 d0).
4. Real-World Applications
In the Real World
- eSewa (Nepal):
- Uses BCD to encode transaction amounts (e.g., ₹500 →
0101 0000 0000). - ASCII for text messages (e.g., "Payment successful" → 7-bit ASCII per character).
- Uses BCD to encode transaction amounts (e.g., ₹500 →
- WhatsApp (Global):
- Converts text to ASCII/Unicode for transmission.
- Uses parity bits in low-level protocols to detect corrupted packets.
- Ncell SMS (Nepal):
- Employs Hamming codes to ensure SMS delivery even with noisy signals.
- Example: If
1001101(Hamming-encoded "5") arrives as1011101, the syndrome111(7) points to bit 7 (d4), correcting it to1001101.
Worked Example: Ncell SMS Error Correction
Transmitted: 1001101 (Hamming-encoded "5").
Received: 1011101 (bit 3 flipped).
Syndrome Calculation:
r1' = 1 ⊕ 1 ⊕ 1 = 1r2' = 1 ⊕ 0 ⊕ 1 = 0r4' = 1 ⊕ 0 ⊕ 1 = 0Syndrome:100(binary) = 4 → Flip bit 4 (d1). Corrected:1001101(original).
5. Exam Tip
- Design Questions:
- Always start with a truth table for converters (BCD ↔ Excess-3, Gray ↔ Binary).
- Use K-maps to simplify logic (group adjacent 1s/0s).
- Draw logic diagrams with standard gate symbols (AND, OR, XOR).
- Short Notes:
- For ASCII: Mention 7/8 bits, printable/control characters, and universal use.
- For parity/Hamming: Define syndrome and give a 4-bit example.
- Applications:
- Link BCD to calculators/eSewa, Gray code to shaft encoders, and Hamming to Ncell SMS.
- Common Pitfalls:
- Forgetting to exclude invalid BCD codes (1010–1111) in conversions.
- Misplacing parity bits (e.g., adding parity to LSB instead of MSB).
- In Hamming codes, syndrome = r4 r2 r1 (not r1 r2 r4).
6. Comparison Table: Key Coding Systems
| Code | Type | Bits | Use Case | Example |
|---|---|---|---|---|
| BCD (8421) | Weighted | 4 | Decimal input (calculators) | 5 → 0101 |
| Excess-3 | Weighted | 4 | Arithmetic simplification | 5 → 1010 |
| Gray | Non-weighted | 4 | Error-prone transmission | 5 → 0111 |
| ASCII | Alphanumeric | 7/8 | Text processing | 'A' → 1000001 |
| Hamming | Error-correcting | 7+ | Reliable data storage/comms | 1001 → 1001101 |
7. Practice Problems
- Design a BCD-to-Gray code converter with truth table and logic diagram.
- Encode "BIT" using ASCII and calculate even parity for each character.
- Detect and correct the error in the received Hamming code
1100111(original:1001). - Why does Excess-3 avoid invalid codes? Explain with a truth table comparison.
Based on the TU BIT syllabus for Digital Logics (BIT103), unit 5.
Discussion
Loading…