Digital Circuits Cheatsheet
Number Systems
Use this Digital Circuits reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Overview
Digital circuits operate on discrete voltage levels representing binary digits (bits). Use this quick reference after a programming language course when you want to understand what integers, characters, addresses, and overflow look like under the code. Understanding number systems is essential for interpreting data, addresses, and encodings at the hardware level.
Positional Number Systems
Every positional system has a radix (base). A number's value is the sum of each digit multiplied by the base raised to its position power.
| System | Base | Digits | Prefix/Suffix |
|---|---|---|---|
| Binary | 2 | 0, 1 | 0b or subscript ₂ |
| Octal | 8 | 0–7 | 0o or subscript ₈ |
| Decimal | 10 | 0–9 | (none) or subscript ₁₀ |
| Hexadecimal | 16 | 0–9, A–F | 0x or subscript ₁₆ |
General formula: (dₙdₙ₋₁…d₁d₀)ᵣ = Σ dᵢ × rⁱ
Example — binary 1011₂: 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11₁₀
Binary ↔ Decimal Conversion
Decimal → Binary (successive division)
Divide by 2 repeatedly; remainders (bottom-up) form the binary number.
45 ÷ 2 = 22 R 1 (LSB) 22 ÷ 2 = 11 R 0 11 ÷ 2 = 5 R 1 5 ÷ 2 = 2 R 1 2 ÷ 2 = 1 R 0 1 ÷ 2 = 0 R 1 (MSB) 45₁₀ = 101101₂
Decimal → Binary (fractions, successive multiplication)
Multiply fraction by 2; integer parts (top-down) form the binary fraction.
0.625 × 2 = 1.25 → 1 0.25 × 2 = 0.5 → 0 0.5 × 2 = 1.0 → 1 0.625₁₀ = 0.101₂
Hexadecimal ↔ Binary
Each hex digit maps to exactly 4 bits.
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Example: 0xAF = 1010 1111₂ = 175₁₀
Signed Number Representations
Sign-Magnitude
MSB is the sign bit (0 = positive, 1 = negative). Two representations of zero (+0 and −0).
| Decimal | 4-bit Sign-Magnitude |
|---|---|
| +5 | 0101 |
| −5 | 1101 |
| +0 | 0000 |
| −0 | 1000 |
One's Complement
Negate by flipping all bits. Still has two zeros.
| Decimal | 4-bit One's Complement |
|---|---|
| +5 | 0101 |
| −5 | 1010 |
Two's Complement (standard)
Negate by flipping all bits and adding 1. One representation of zero; used in virtually all modern hardware.
| Decimal | 4-bit Two's Complement |
|---|---|
| +7 | 0111 |
| +1 | 0001 |
| 0 | 0000 |
| −1 | 1111 |
| −7 | 1001 |
| −8 | 1000 |
Range for n bits: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
Quick negate: flip bits, add 1. Example: +5 = 0101 → flip → 1010 → +1 → 1011 = −5 ✓
Binary Arithmetic
Addition
Carry rules identical to decimal but base-2:
0111 (+7) + 0001 (+1) ------ 1000 (+8) Carry chain: 1 1 1 0
Overflow Detection (Two's Complement)
Overflow occurs when adding two numbers of the same sign and getting the opposite sign.
- Two positive numbers → negative result: overflow
- Two negative numbers → positive result: overflow
- Mixed signs: never overflow
Subtraction via Two's Complement
A − B = A + (−B) = A + (~B + 1)
7 − 3 = 7 + (−3) 0111 + 1101 (−3 in two's complement) ------ 10100 → ignore carry → 0100 = 4 ✓
Binary Coded Decimal (BCD)
Each decimal digit encoded separately in 4 bits (0000–1001 valid; 1010–1111 invalid).
| Decimal | BCD |
|---|---|
| 0 | 0000 |
| 5 | 0101 |
| 9 | 1001 |
| 25 | 0010 0101 |
| 99 | 1001 1001 |
BCD is used in financial and display hardware where human-readable digits matter more than compact storage.
Character Encodings
| Encoding | Bits | Notes |
|---|---|---|
| ASCII | 7 (8 w/ parity) | 128 characters; 'A' = 0x41 = 65 |
| Extended ASCII | 8 | 256 characters |
| Unicode (UTF-8) | 8–32 variable | Backward-compatible with ASCII |
ASCII layout landmarks:
0x30–0x39→ digits '0'–'9'0x41–0x5A→ uppercase 'A'–'Z'0x61–0x7A→ lowercase 'a'–'z'- Lowercase = uppercase +
0x20(set bit 5)
Powers of 2 Reference
| Power | Value | Common name |
|---|---|---|
| 2¹⁰ | 1 024 | 1 Ki (kibi) |
| 2²⁰ | 1 048 576 | 1 Mi (mebi) |
| 2³⁰ | 1 073 741 824 | 1 Gi (gibi) |
| 2³² | 4 294 967 296 | 4 G (IPv4 address space) |
| 2⁶⁴ | ≈ 1.84 × 10¹⁹ | 64-bit address space |