Digital LogicUnit 110 min read
Digital Logic Basics: Signals, Number Systems & Boolean Algebra
Unit 1 of Digital Logic covers the foundational concepts of digital systems, including analog vs. digital signals, binary/hexadecimal/octal number systems, Gray code, BCD, and Boolean algebra's role in digital design—essential for designing circuits and understanding modern computing hardware.
TAKEAWAYS:
- Digital logic uses discrete signals (binary) to represent data, unlike analog signals (continuous), enabling reliable computation in devices like smartphones and computers.
- The binary system (base-2) is the backbone of digital systems, with conversions to decimal, hexadecimal (base-16), and octal (base-8) critical for programming and hardware design.
- Gray code minimizes errors in data transmission by changing only one bit between consecutive numbers, used in encoders like those in eSewa’s QR code generation.
- Boolean algebra (AND, OR, NOT) forms the mathematical foundation for designing logic gates and circuits, while the binary system is purely numerical.
- Complements (1’s and 2’s) simplify subtraction and arithmetic operations in hardware, like how Khalti processes transactions using binary arithmetic for speed.
- Positional number systems (binary, decimal, hex) enable efficient data representation, while floating-point formats (IEEE 754) handle real-world precision in scientific calculations.
1. Analog vs. Digital Signals
Digital logic operates on discrete signals (binary: 0 or 1), unlike analog signals (continuous, like sound waves). This distinction is critical for modern electronics.
Key Definitions
- Analog Signal: A continuous signal representing physical quantities (e.g., temperature, voltage).
flowchart LR A["Analog Signal"] -->|"Example"| B["Sound Wave"] A -->|"Characteristics"| C["Continuous\nInfinite values"]
- Digital Signal: Discrete values (0 or 1) representing data in binary form.
flowchart LR A["Digital Signal"] -->|"Example"| B["Computer Data"] A -->|"Characteristics"| C["Discrete\nTwo states (0/1)"]
Why Digital?
| Advantage | Disadvantage |
|---|---|
| Noise immunity | Requires conversion (ADC/DAC) |
| Easier storage/processing | Limited precision in analog-to-digital conversion |
| Reliable transmission | Complex hardware for high-speed signals |
2. Number Systems in Digital Logic
Digital systems use positional number systems to represent data. The most common are:
- Binary (Base-2): Used directly by computers.
- Decimal (Base-10): Human-readable.
- Hexadecimal (Base-16): Compact representation of binary.
- Octal (Base-8): Used in older systems.
Binary Number System
- Digits: 0 and 1.
- Weight: Each bit represents where is its position (right to left, starting at 0).
- Example: .
Worked Example: Convert to Decimal
Hexadecimal (Hex) and Octal Systems
| System | Base | Digits | Use Case |
|---|---|---|---|
| Binary | 2 | 0, 1 | Computer hardware |
| Decimal | 10 | 0-9 | Human communication |
| Hexadecimal | 16 | 0-9, A-F | Memory addressing (e.g., RAM) |
| Octal | 8 | 0-7 | Legacy systems (e.g., Unix) |
Worked Example: Convert to Binary
- Break into digits: .
- Convert each to 4-bit binary:
- Combine: .
3. Gray Code
Gray code is a non-weighted binary code where only one bit changes between consecutive numbers. Used in:
- Error-prone systems (e.g., encoders in eSewa’s QR code scanners).
- Avoiding glitches in digital circuits.
Gray Code Conversion
Method:
- Start with binary number.
- For each bit (left to right), XOR with the next higher bit.
Example: Convert to Gray Code
| Binary | Step 1 (XOR with next bit) | Gray Code |
|---|---|---|
| 1 | - | 1 |
| 0 | 1 XOR 0 = 1 | 1 |
| 1 | 0 XOR 1 = 1 | 1 |
| 1 | 1 XOR 1 = 0 | 0 |
| 0 | 1 XOR 0 = 1 | 1 |
| 1 | 0 XOR 1 = 1 | 1 |
| 0 | 1 XOR 0 = 1 | 1 |
Final Gray Code: .
4. Binary-Coded Decimal (BCD)
BCD represents decimal digits (0-9) using 4-bit binary. Each decimal digit is stored as a separate binary number.
| Decimal | BCD (4-bit) |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| ... | ... |
| 9 | 1001 |
Example: .
Use Case: ATM machines (Nepal’s Nabil Bank ATMs) use BCD to display decimal numbers accurately.
5. Complements in Digital Logic
Complements simplify subtraction and arithmetic operations in hardware.
Types of Complements
- 1’s Complement: Invert all bits (0 → 1, 1 → 0).
- Example: → .
- 2’s Complement: Add 1 to the least significant bit (LSB) of the 1’s complement.
- Example: → (1’s) → (2’s).
Worked Example: Subtract Using 2’s Complement
- Convert to 8-bit binary:
- Find 2’s complement of :
- → (invert) → (add 1).
- Add to :
00001101 + 11111011 --------- 10001000 - Discard overflow: (incorrect due to end-around carry; correct result is ).
Real-World Tie-In:
- Khalti’s transaction processing uses 2’s complement arithmetic for fast subtraction in payment validations.
6. Boolean Algebra vs. Binary System
| Feature | Boolean Algebra | Binary System |
|---|---|---|
| Purpose | Mathematical foundation for logic gates | Numerical representation of data |
| Operations | AND, OR, NOT, NAND, NOR, XOR | Addition, subtraction, multiplication |
| Use Case | Designing circuits (e.g., Ncell’s SIM cards) | Storing data (e.g., YouTube’s video buffers) |
Example of Boolean Expression:
7. IEEE 754 Floating-Point Representation
Used in scientific calculations (e.g., NEPSE stock price fluctuations).
Single Precision (32-bit)
| Field | Bits | Range |
|---|---|---|
| Sign | 1 | 0 (positive), 1 (negative) |
| Exponent | 8 | Bias = 127 |
| Mantissa | 23 | Fractional part |
Worked Example: Convert to IEEE 754 Double Precision
- Binary Representation:
- Integer part: .
- Fractional part: (first 53 bits).
- Combined: .
- Normalize: Shift left to get .
- Exponent: (11 bits).
- Mantissa: Drop leading 1 and take next 52 bits: .
- Final Representation:
- Sign: 0 (positive).
- Exponent:
10000000101. - Mantissa:
000000010110011001100110011001100110011001100110011. - Hex:
402E35F15F15F15F.
In the Real World
eSewa’s QR Code Generation
- Uses Gray code to minimize errors in QR code scanning, ensuring accurate transaction processing even with slight distortions.
Khalti’s Transaction Arithmetic
- Relies on 2’s complement arithmetic for fast subtraction in validating payment amounts, reducing processing time.
Ncell’s SIM Card Authentication
- Employs Boolean algebra in logic gates to verify user credentials securely during network access.
NEPSE Stock Price Displays
- Uses IEEE 754 floating-point to represent fractional stock prices with high precision, critical for financial calculations.
Daraz’s Order Queue Management
- Binary counters track order status (e.g.,
001= processing,100= shipped), enabling efficient inventory management.
- Binary counters track order status (e.g.,
Exam Tip
Memorize Conversions:
- Practice converting between binary, decimal, hex, and octal under time pressure. Use shortcuts like grouping binary into nibbles (4 bits) for hex conversion.
- Example: .
Gray Code Tricks:
- For exams, use the XOR method for conversion. If stuck, write out the binary and Gray code side-by-side to spot patterns.
Complement Operations:
- Always add 1 to the LSB after inverting bits for 2’s complement. Double-check subtraction by verifying the result’s sign bit.
IEEE 754 Pitfalls:
- Remember the bias (127 for single, 1023 for double precision). Forgetting to add it will lead to incorrect exponents.
- Shortcut: For positive numbers, exponent bits = actual exponent + bias.
Boolean vs. Binary:
- Boolean algebra is about logic operations (AND, OR), while binary is about numbers. Mixing them up in definitions will lose marks.
Real-World Applications:
- Examiners love tying concepts to local examples (e.g., "How does Khalti use 2’s complement?"). Prepare 2-3 such examples per topic.
Final Note: This unit is the foundation of digital logic. Master conversions, Gray code, and complements first—they appear in every subsequent unit. Use flashcards for binary-hex-octal conversions and practice IEEE 754 with online calculators. Good luck!
Based on the TU BCA syllabus for Digital Logic (CACS103), unit 1.
Discussion
Loading…