Digital LogicsUnit 18 min read
Digital Logic Basics: Number Systems, Codes & Binary Fundamentals
Unit 1 of Digital Logics: Covers binary/decimal/octal/hexadecimal conversions, BCD/Excess-3/Gray codes, weighted vs non-weighted codes, and real-world applications in computing, communications, and embedded systems—foundational for all digital circuit design.
TAKEAWAYS:
- Digital logic uses binary (base-2) as its universal language, while humans work in decimal (base-10)—conversions between them are essential for programming and hardware design.
- Weighted codes (like BCD) assign positional values, while non-weighted codes (like Gray) prioritize error resistance or simplicity in transitions.
- Complement methods (1’s and 2’s complement) enable subtraction via addition, a core operation in ALUs and CPUs.
- Real-world systems (e.g., eSewa’s payment processing, Ncell’s SIM authentication) rely on these conversions and codes for data integrity and efficiency.
- Exam focus: Conversions (decimal ↔ binary/octal/hex), code definitions (BCD, Excess-3), and designing simple combinational circuits (e.g., 1’s/2’s complement generators).
1. Digital vs Analog Systems
Digital systems represent data as discrete signals (0s and 1s), while analog systems use continuous signals (e.g., voltage levels). Digital logic is the backbone of computers, smartphones, and embedded systems because:
- Immunity to noise: Digital signals (0V/5V) are less affected by interference than analog signals.
- Easier storage/processing: Binary data can be stored in memory (RAM/ROM) and manipulated by logic gates.
- Scalability: Digital circuits can be miniaturized (e.g., transistors in CPUs) without losing signal integrity.
2. Number Systems in Digital Logic
Digital systems use four primary bases:
- Binary (Base-2): Uses digits
0and1. Fundamental for computers. - Decimal (Base-10): Human-readable (digits
0–9). - Octal (Base-8): Groups binary digits into 3-bit chunks (e.g.,
101010→52₈). - Hexadecimal (Base-16): Groups binary digits into 4-bit chunks (e.g.,
11010010→D2₁₆). Used in memory addressing and programming.
Conversion Methods
| From | To | Method |
|---|---|---|
| Decimal → Binary | Division by 2: Remainders give binary digits (LSB first). | |
| Binary → Decimal | Weighted sum: . | |
| Decimal → Octal/Hex | Division by 8/16: Remainders give digits (LSB first). | |
| Octal/Hex → Binary | Grouping: 3 bits per octal digit, 4 bits per hex digit. | |
| Binary → Octal/Hex | Grouping: Pad with leading zeros if needed, then convert each group. |
Worked Example: Convert (51966.57)₁₀ to Hexadecimal
- Integer part (51966):
- Divide by 16:
51966 ÷ 16 = 3247(R: E)3247 ÷ 16 = 202(R: 15 → F)202 ÷ 16 = 12(R: 12 → C)12 ÷ 16 = 0(R: 12 → C) - Read remainders upward: CCF1E₁₆.
- Divide by 16:
- Fractional part (0.57):
- Multiply by 16:
0.57 × 16 = 9.12→ 90.12 × 16 = 1.92→ 10.92 × 16 = 14.72→ E (stop after 3 digits). - Combine: CCF1E.91E₁₆.
- Multiply by 16:
3. Weighted and Non-Weighted Codes
A. Weighted Codes
Assign positional values to digits. Examples:
- Binary-Coded Decimal (BCD): Encodes each decimal digit (0–9) as 4-bit binary.
- Example:
5→0101(BCD), not101(pure binary). - Advantages: Easy conversion to/from decimal.
- Disadvantages: Inefficient (6 bits per decimal digit vs. 4 in pure binary).
- Example:
- Excess-3 Code: BCD +3 to each digit (e.g.,
0→0011,9→1110).- Use: Error detection in communication systems (e.g., Ncell’s SMS encoding).
B. Non-Weighted Codes
No positional values; designed for specific applications.
- Gray Code: Single-bit change between consecutive numbers. Used in:
- Rotary encoders (e.g., eSewa’s QR code scanners to avoid misreading).
- Error-prone environments (e.g., NTC’s power grid monitoring).
- Alphanumeric Codes: Encode letters/numbers (e.g., ASCII, Unicode).
Worked Example: BCD to Excess-3 Converter
Input (BCD): A B C D (4-bit)
Output (Excess-3): A+3 B+3 C+3 D+3 (mod 10).
Truth Table:
| A B C D | Excess-3 Output |
|---|---|
| 0000 | 0011 |
| 0001 | 0100 |
| 0100 | 0111 |
| 0101 | 1000 |
Logic Diagram:
A B C D
| | | |
--------
0 0 1 1 (3)
0 1 0 0 (4)
Circuit: Use 4 1-bit adders with constant input 11 (3 in binary).
4. Complement Methods
Used for subtraction via addition (key in ALUs).
A. 1’s Complement
- Definition: Invert all bits (e.g.,
1010→0101). - Subtraction:
A - B = A + (1’s complement of B) + 1. - Limitation: Two representations for zero (
0000and1111).
B. 2’s Complement
- Definition: Add 1 to the 1’s complement (e.g.,
1010→0101→0110). - Advantages:
- Single representation for zero.
- Simplifies hardware (e.g., Nepal Rastra Bank’s loan interest calculators use 2’s complement for financial arithmetic).
Worked Example: Subtract 5 - 3 using 4-bit 2’s Complement
- Represent
5and3in 4-bit:5=01013=0011
- Find 2’s complement of
3:- 1’s complement:
1100 - Add 1:
1101
- 1’s complement:
- Add
5+1101:0101 (5) + 1101 (-3) -------- 10010 (discard overflow) → `0010` (2)
5. Real-World Applications
A. eSewa’s Payment Processing
- Binary/Octal/Hex Conversions: Used internally to process transaction IDs (e.g., a 32-bit ID like
0xA1B2C3D4). - BCD Codes: Store amounts (e.g.,
₹5,200→0101 0010 0000 0000in BCD).
B. Ncell’s SIM Authentication
- Gray Code: Encodes SIM card positions in rotary dialers to avoid misreading during swaps.
- Hexadecimal: Used in IMEI numbers (e.g.,
490154203245678→ grouped as49 01 54 20 32 45 67 8).
C. Daraz’s Order Queue System
- Binary Counters: Track order IDs (e.g.,
0001to1111for orders 1–15). - Priority Encoders: Assign urgency levels (e.g.,
1010for "high-priority").
D. Kathmandu Traffic Light Control
- Sequential Logic: Uses binary counters to cycle through
00(red),01(amber),10(green). - Decoders: Convert binary states to activate specific lights.
6. Exam Tip: How to Score Full Marks
- Conversions:
- Show all intermediate steps (e.g., grouping for octal/hex).
- Label each step clearly (e.g., "Binary → Octal: Group into 3 bits").
- Code Design:
- Truth tables: Include all possible inputs (e.g., 16 rows for 4-bit BCD).
- Logic diagrams: Use standard gate symbols (AND, OR, NOT) and label inputs/outputs.
- Example: For a 1’s complement generator, draw:
A B C D | | | | -------- NOT NOT NOT NOT
- Complement Methods:
- For subtraction, always show the 2’s complement process (1’s complement + 1).
- Highlight the final carry-out (discarded in final result).
- Real-World Tie-Ins:
- Link questions to eSewa payments, Ncell SIMs, or traffic lights to show practical understanding.
- Example: "This BCD-to-7-segment decoder is used in eSewa’s receipt printers to display transaction amounts."
Final Note: Master conversions and code definitions—these are 50% of Unit 1 exam questions. Practice designing small circuits (e.g., 1’s/2’s complement generators) to build intuition for Unit 3 (Combinational Logic).
Based on the TU BIT syllabus for Digital Logics (BIT103), unit 1.
Discussion
Loading…