Elective Digital Logic

Digital LogicUnit 17 min read

Digital Systems & Number Systems: Basics, Codes, and Conversions

Unit 1 of Digital Logic covers the foundational concepts of digital systems (vs. analog), number systems (binary, octal, hexadecimal, Gray code), weighted/non-weighted codes, and conversion techniques—essential for designing circuits and interpreting data in computers, mobile apps, and embedded systems.

TAKEAWAYS:

  • Digital systems use discrete signals (0/1) and are preferred for accuracy, flexibility, and error handling over analog systems.
  • Number systems (binary, octal, hexadecimal) enable efficient data representation and processing in computers.
  • Gray code minimizes errors in sequential data transmission by changing only one bit per step.
  • Conversion between number systems (binary ↔ decimal, binary ↔ octal/hex) is critical for programming and hardware design.
  • Weighted codes (e.g., BCD) and non-weighted codes (e.g., Gray) serve distinct roles in data storage and transmission.
  • Real-world applications include error detection in eSewa transactions, data encoding in WhatsApp messages, and efficient routing in Pathao’s GPS systems.

1. Analog vs. Digital Systems: Key Differences

Digital systems represent data as discrete values (0/1), while analog systems use continuous signals (e.g., voltage levels). Below is a comparison table:

Feature Analog System Digital System
Signal Type Continuous (e.g., sine waves) Discrete (0/1, pulses)
Noise Immunity Poor (susceptible to interference) High (error correction possible)
Flexibility Limited (hardware-dependent) High (software programmable)
Storage Difficult (degrades over time) Easy (non-volatile memory)
Examples Thermometer, old radio receivers Computers, smartphones, digital clocks

Why digital systems dominate modern tech?

  • Accuracy: Discrete values resist noise (e.g., Ncell’s signal boosters use digital error correction).
  • Scalability: Software updates (e.g., Khalti’s fraud detection) are easier than hardware changes.
  • Integration: Digital circuits (e.g., Daraz’s payment gateways) can be combined flexibly using logic gates.

2. Number Systems: Binary, Octal, Hexadecimal, and Gray Code

2.1 Binary System (Base-2)

  • Uses two symbols: 0 (low voltage) and 1 (high voltage).
  • Example: The binary 1010 represents .
graph LR
    A["Binary"] --> B["Decimal<br/>(1010 = 10)"]
    A --> C["Octal<br/>(1010 = 12)"]
    A --> D["Hexadecimal<br/>(1010 = A)"]

Real-world use:

  • WhatsApp messages are encoded in binary for transmission over networks.
  • Bank ATMs use binary to process transactions (e.g., 1101 = ₹13 in BCD).

2.2 Octal (Base-8) and Hexadecimal (Base-16)

  • Octal: Groups binary digits into 3-bit chunks (e.g., 101 010 → 52_8).
  • Hexadecimal: Groups into 4-bit chunks (e.g., 1101 0010 → D2_H).
08162431Bit 34 bitsBit 24 bitsBit 14 bitsBit 04 bits
Octal grouping: 4-bit binary chunks for octal conversion

Conversion shortcuts:

Binary Octal Hexadecimal
0000 0 0
0001 1 1
... ... ...
1111 7 F

Example: Convert (11010110)_2 to octal and hexadecimal.

  1. Octal: Split into 1 101 011 0 → 1530_8.
  2. Hex: Split into 1101 0110 → D6_H.

Real-world use:

  • NEPSE stock codes (e.g., NTC shares) are often represented in hexadecimal for compact storage.
  • YouTube video IDs (e.g., dQw4w9WgXcQ) use hexadecimal for URL efficiency.

2.3 Gray Code (Non-Weighted Code)

  • Property: Only one bit changes between consecutive numbers (e.g., 000 → 001 → 011).
  • Advantage: Reduces errors in sequential data (e.g., eSewa transaction IDs, GPS coordinates).
G1G2G3AB
3-bit Gray code generator from binary inputs A,B

Conversion from Binary to Gray:

  1. Start with MSB.
  2. Each subsequent bit = XOR of current binary bit and previous binary bit.

Example: Convert 1011_2 to Gray.

Binary:  1 0 1 1
Gray:    1 (1) 1 (1⊕0) 0 (0⊕1) 1 (1⊕1)
Result: 1101 (Gray)

Real-world use:

  • Pathao’s driver location tracking uses Gray code to minimize GPS error during rapid movement.
  • Medical devices (e.g., ECG monitors) use Gray code to avoid misreading heart rate spikes.

3. Weighted vs. Non-Weighted Codes

Code Type Definition Example Use Case
Weighted Each bit has a positional value. BCD (8421 code) Digital clocks, calculators
Non-Weighted No positional value; error-resistant. Gray code Encoders, error-prone systems

Example of BCD (Binary-Coded Decimal):

  • Decimal 5 → 0101_BCD (not 101_2).
  • Used in bank ATMs to display amounts (e.g., ₹123 → 0001 0010 0011_BCD).

4. Number System Conversions: Worked Examples

Example 1: Binary to Decimal

Convert (101011)_2 to decimal.

1×2⁵ + 0×2⁴ + 1×2³ + 0×2² + 1×2¹ + 1×2⁰
= 32 + 0 + 8 + 0 + 2 + 1 = 43_{10}

Example 2: Decimal to Binary (Division Method)

Convert 47_{10} to binary.

47 ÷ 2 = 23 R1
23 ÷ 2 = 11 R1
11 ÷ 2 = 5  R1
5  ÷ 2 = 2  R1
2  ÷ 2 = 1  R0
1  ÷ 2 = 0  R1
Read remainders upward: 101111_2

Example 3: Binary to Octal/Hex (Grouping Method)

Convert (110101101)_2 to octal and hex.

  1. Octal: Group into 3 bits → 11 010 110 1 → 3 2 6 1 → 3261_8.
  2. Hex: Group into 4 bits → 0001 1010 1101 → 1 A D → 1AD_H.

Example 4: Gray to Binary

Convert (1101)_Gray to binary.

Gray:   1 1 0 1
Binary: 1 (1) 0 (1⊕1) 0 (0⊕1) 1 (1⊕0)
Result: 1001_2 (9_{10})

5. Real-World Applications

Case Study 1: eSewa Transaction IDs

  • Problem: Sequential transaction IDs must avoid errors during transmission.
  • Solution: Gray code ensures only one bit changes per ID increment (e.g., 0000 → 0001 → 0011).
  • Outcome: Reduces fraud risk in ₹10,000+ transfers.

Case Study 2: Daraz Order Processing

  • Problem: Orders arrive in bursts; priority queues needed.
  • Solution: Binary-coded order IDs (e.g., 00101) help sort and process orders efficiently.
  • Outcome: Faster delivery in Kathmandu’s congested areas.

Case Study 3: NTC’s Signal Boosting

  • Problem: Analog signals degrade over distance.
  • Solution: Digital repeaters convert signals to binary, correct errors, and retransmit.
  • Outcome: Stable 4G in remote villages.

6. Exam Tip: How to Score Full Marks

  1. Definitions: Always define terms precisely (e.g., "Digital systems use discrete signals").
  2. Conversions: Show step-by-step methods (e.g., division for decimal→binary).
  3. Real-world links: Relate answers to Nepali tech (e.g., "Khalti uses binary for transaction logs").
  4. Diagrams: Draw binary-to-octal/hex grouping or Gray code transitions when asked.
  5. Common mistakes to avoid:
    • Forgetting to pad binary with zeros for grouping (e.g., 10101 → 010101 for octal).
    • Misapplying Gray code rules (always XOR adjacent bits).
    • Confusing weighted (BCD) vs. non-weighted (Gray) codes.

gray code transition diagramCircular Gray code wheel showing adjacent bit changes (Image: Superspritz, CC BY-SA 4.0, via Wikimedia Commons)

Based on the PU BE Computer (PU) syllabus for Digital Logic, unit 1.

Discussion

Loading…