Part 2: Introduction to Logic Design
Source: Part-2-Logic+Design.pdf
Formal Definition: An analog signal is a continuous signal that varies over time. A digital signal is a discrete signal with a finite number of values, typically two (0 and 1).
Key Points
- Analog = continuous values, Digital = discrete values
- Binary digital: only 2 values — 0 and 1
- Digital is more noise-immune than analog
- A/D converter: converts analog → digital, D/A converter: digital → analog
- Computers process digital signals internally even if inputs/outputs are analog
⚠️ Common Traps
🧪 Quick Self-Test
Formal Definition: A number system with base/radix $r$ uses $r$ distinct digits. The value of a number $d_n d_{n-1} ... d_1 d_0$ in base $r$ is $\\sum_{i=0}^{n} d_i \\times r^i$.
Decimal (base 10): digits 0–9. What we use daily.
Binary (base 2): digits 0, 1. What computers use.
Octal (base 8): digits 0–7. Compact way to write binary (3 bits = 1 octal digit).
Hexadecimal (base 16): digits 0–9, A–F. Even more compact (4 bits = 1 hex digit).
Key Points
- Binary (base 2): 0, 1 — used in digital circuits
- Octal (base 8): 0-7 — each octal digit = 3 binary digits
- Decimal (base 10): 0-9 — human-readable
- Hex (base 16): 0-9, A(10), B(11), C(12), D(13), E(14), F(15) — each hex digit = 4 binary digits
- The subscript notation: $(1010)_2$ means binary, $(FF)_{16}$ means hex
- MSB = Most Significant Bit (leftmost), LSB = Least Significant Bit (rightmost)
Formulas
Worked Examples
Problem: What is the decimal value of the binary number $(1011)_2$?
- $1 \\times 2^3 = 8$
- $0 \\times 2^2 = 0$
- $1 \\times 2^1 = 2$
- $1 \\times 2^0 = 1$
- Sum: $8 + 0 + 2 + 1 = 11$
Answer: $(1011)_2 = (11)_{10}$
Problem: What is the decimal value of $(2A)_{16}$?
- $A = 10$ in decimal
- $2 \\times 16^1 = 32$
- $10 \\times 16^0 = 10$
- Sum: $32 + 10 = 42$
Answer: $(2A)_{16} = (42)_{10}$
⚠️ Common Traps
🧪 Quick Self-Test
Any base → Decimal: Use the positional value formula (multiply each digit by base^position, sum up).
Decimal → Any base: Repeated division by the target base. The remainders (read bottom to top) give the answer.
Binary ↔ Octal: Group binary digits in 3s (from right). Each group = 1 octal digit.
Binary ↔ Hex: Group binary digits in 4s (from right). Each group = 1 hex digit.
Octal ↔ Hex: Convert through binary as an intermediate step.
Key Points
- To decimal: multiply each digit by base^position, add all up
- From decimal: repeated division, remainders read bottom-to-top
- Binary → Octal: group by 3 bits (pad with leading zeros if needed)
- Binary → Hex: group by 4 bits (pad with leading zeros if needed)
- For fractional parts: multiply by base repeatedly, take integer parts
- Octal ↔ Hex: go through binary (Octal → Binary → Hex or reverse)
Formulas
Worked Examples
Problem: Convert $(25)_{10}$ to binary.
- $25 \div 2 = 12$ remainder $1$
- $12 \div 2 = 6$ remainder $0$
- $6 \div 2 = 3$ remainder $0$
- $3 \div 2 = 1$ remainder $1$
- $1 \div 2 = 0$ remainder $1$
- Read remainders bottom to top: $11001$
Answer: $(25)_{10} = (11001)_2$
Problem: Convert $(10110110)_2$ to hexadecimal.
- Group into 4 bits from right: $1011 \ 0110$
- $0110_2 = 6_{16}$
- $1011_2 = B_{16}$ (since $8+0+2+1 = 11 = B$)
- Result: $B6$
Answer: $(10110110)_2 = (B6)_{16}$
Problem: Convert $(10110110)_2$ to octal.
- Group into 3 bits from right: $10 \ 110 \ 110$
- Pad leftmost group: $010 \ 110 \ 110$
- $010_2 = 2_8$
- $110_2 = 6_8$
- $110_2 = 6_8$
- Result: $266$
Answer: $(10110110)_2 = (266)_8$
⚠️ Common Traps
🧪 Quick Self-Test
Formal Definition: For a number $N$ with $n$ digits in base $r$: the $r$'s complement is $r^n - N$, and the $(r-1)$'s complement is $r^n - 1 - N$.
1's Complement: Flip all bits (0→1, 1→0). That's it!
2's Complement: Flip all bits, then add 1. OR: find the rightmost 1, keep it and everything to the right, flip everything to the left.
2's complement is used to represent negative numbers in computers. It allows subtraction to be done using addition hardware.
Key Points
- 1's complement: flip all bits (0↔1)
- 2's complement: flip all bits + add 1 (OR: 1's complement + 1)
- 2's complement shortcut: from right, keep bits until first 1 (inclusive), then flip the rest
- 2's complement is used for signed number representation in computers
- In n-bit 2's complement: range is $-2^{n-1}$ to $2^{n-1}-1$
- MSB = sign bit: 0 = positive, 1 = negative (in signed representation)
- For decimal: 9's complement (flip each digit from 9), 10's complement = 9's + 1
Formulas
Worked Examples
Problem: Find the 1's and 2's complement of $(1010)_2$.
- 1's complement: flip all bits → $0101$
- 2's complement: 1's complement + 1 → $0101 + 1 = 0110$
Answer: 1's complement = $0101$, 2's complement = $0110$
Problem: Subtract $(0111)_2$ from $(1010)_2$ using 2's complement.
- Find 2's complement of $0111$: flip → $1000$, add 1 → $1001$
- Add: $1010 + 1001 = 10011$
- There is a carry out (5th bit) — discard it
- Result: $0011 = 3_{10}$
- Verify: $10 - 7 = 3$ ✓
Answer: $(1010)_2 - (0111)_2 = (0011)_2 = 3_{10}$
⚠️ Common Traps
🧪 Quick Self-Test
Gray Code: A binary code where consecutive numbers differ by only 1 bit. Used in Karnaugh maps and rotary encoders to prevent glitches.
Excess-3: Add 3 to each decimal digit, then convert to 4-bit binary. Self-complementing code (9's complement = 1's complement of the code).
Key Points
- BCD: each decimal digit → 4 bits independently (0→0000, 9→1001)
- BCD only uses codes 0000–1001; codes 1010–1111 are INVALID in BCD
- Gray code: adjacent values differ by exactly 1 bit
- Binary to Gray: MSB stays same, each next bit = XOR of adjacent binary bits
- Gray to Binary: MSB stays same, each next bit = XOR of previous result with current Gray bit
- Excess-3: add 3 to decimal digit, then convert to 4-bit binary
- Excess-3 is self-complementing: 9's complement of decimal digit = 1's complement of Excess-3 code
Formulas
Worked Examples
Problem: Convert decimal 47 to BCD.
- Digit 4 → $0100$
- Digit 7 → $0111$
- Concatenate: $0100 \ 0111$
Answer: $(47)_{10} = (0100 \ 0111)_{BCD}$
Problem: Convert binary $1011$ to Gray code.
- MSB stays: $G_3 = B_3 = 1$
- $G_2 = B_3 \oplus B_2 = 1 \oplus 0 = 1$
- $G_1 = B_2 \oplus B_1 = 0 \oplus 1 = 1$
- $G_0 = B_1 \oplus B_0 = 1 \oplus 1 = 0$
Answer: $(1011)_2 = (1110)_{Gray}$