IT 233

Digital Logic

TU BIM · Semester 2 · BIM curriculum effective from 2021

Requirement
required
Credits
3
Study Guide
6 units available

Chapter notes

Authoritative study guide across 6 syllabus units

Open a unit to read its study notes.

Unit 1: Binary Systems· 6 LHs· ~8 marks

Pass path: Learn number base conversions and 2’s complement subtraction in Part 1 and Part 2. Top path: Master binary codes (Gray code vs Excess-3) and fractional base conversions in Part 3 and Part 4.

Part 1: Core Concepts (2 Marks)

  • ★ Base (Radix) of a Number System: The total number of distinct symbols or digits utilized in that system (Binary: r=2r=2, Octal: r=8r=8, Decimal: r=10r=10, Hexadecimal: r=16r=16). A number is evaluated by polynomial expansion: ∑di×ri\sum d_i \times r^i.
  • ★ 2’s Complement of a Binary Number: Obtained by taking the 1’s complement (inverting all bits: 0→1,1→00 \to 1, 1 \to 0) and adding 1 to the least significant bit (LSB):
    2’s Complement=1’s Complement+1\text{2's Complement} = \text{1's Complement} + 1
  • ★ Gray Code (Unit-Distance Code): An unweighted non-arithmetic binary code where consecutive numerical values differ by only a single bit, eliminating multi-bit switching glitches in rotary optical encoders.

Part 2: Structural Frameworks (10 Marks)

1. Binary Subtraction Using 2’s Complement (M−NM - N)

When performing subtraction M−NM - N using nn-bit 2’s complement arithmetic:

  1. Express both MM and NN with the same number of bits (nn).
  2. Compute the 2’s complement of the subtrahend (NN).
  3. Add the 2’s complement of NN to the minuend (MM):
    Sum=M+[2n−N]=M−N+2n\text{Sum} = M + [2^n - N] = M - N + 2^n
  4. Evaluate the End-Carry Bit:
    • Case 1 (Carry Occurs): If an end-carry of 1 is generated, discard the carry. The result is positive and represented directly in standard binary (M≥NM \ge N).
    • Case 2 (No Carry): If no end-carry occurs, the result is negative (M<NM < N). The true magnitude is obtained by taking the 2’s complement of the resulting sum and appending a negative sign.

Part 3: Distinction Tables

Binary Codes Comparison: BCD (8421) vs. Excess-3 vs. Gray Code

Parameter BCD (8421 Code) Excess-3 Code Gray Code
Code Category Weighted positional arithmetic code Non-weighted arithmetic code Non-weighted unit-distance code
Mathematical Derivation Direct 4-bit binary representation of decimal digits (00–99) BCD+3\text{BCD} + 3 (adds 0011 to each decimal digit) Derived via XOR shifts (gi=bi⊕bi+1g_i = b_i \oplus b_{i+1})
Self-Complementing No (9’s complement not obtained by inversion) Yes (1’s complement yields 9’s complement) No
Consecutive Bit Change Up to 3 or 4 bits change simultaneously Up to 3 bits change simultaneously Strictly 1 bit changes between adjacent values

Part 4: Worked Problems & Exam Traps

Solved Ladder: 2’s Complement Subtraction

Problem: Subtract (23)10(23)_{10} from (14)10(14)_{10} using 8-bit 2’s complement arithmetic.

Step-by-step Solution:

  1. Convert to 8-bit binary:
    • Minuend M=14=(00001110)2M = 14 = (00001110)_2
    • Subtrahend N=23=(00010111)2N = 23 = (00010111)_2
  2. Find 2’s complement of NN:
    • 1’s complement of N=11101000N = 11101000
    • 2’s complement =11101000+1=11101001= 11101000 + 1 = 11101001
  3. Add MM and 2’s complement of NN:
    \begin{array}{r@{\quad}l} & 00001110 \\ + & 11101001 \\ \hline & 11110111 \end{array}
  4. End-Carry Evaluation:
    • There is no end-carry   ⟹  \implies The result is negative.
    • Take 2’s complement of 1111011111110111: 1’s complement =00001000= 00001000 2’s complement =00001000+1=(00001001)2=910= 00001000 + 1 = (00001001)_2 = 9_{10}
  5. Append negative sign: Result is −9-9 (Verifies: 14−23=−914 - 23 = -9).

Students lose marks here because when no end-carry occurs, they write down the raw sum as positive instead of taking its 2’s complement to find the negative magnitude.

Binary Complements and Overflow Arithmetic

In nn-bit signed representation:

  • 1’s Complement: Invert every bit (0↔10 \leftrightarrow 1).
  • 2’s Complement: Take 1’s complement and add 11.
  • Signed Range: For nn bits, the range is [−2n−1,2n−1−1][-2^{n-1}, 2^{n-1} - 1].
  • Arithmetic Overflow: Occurs when adding two numbers of the same sign produces a result of opposite sign. In hardware, overflow is flagged by V=Cin⊕CoutV = C_{in} \oplus C_{out} at the most significant bit (MSB).