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.

SystemBaseDigitsPrefix/Suffix
Binary20, 10b or subscript ₂
Octal80–70o or subscript ₈
Decimal100–9(none) or subscript ₁₀
Hexadecimal160–9, A–F0x 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.251
0.25  × 2 = 0.50
0.5   × 2 = 1.01
0.625₁₀ = 0.101

Hexadecimal ↔ Binary

Each hex digit maps to exactly 4 bits.

HexBinaryDecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

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).

Decimal4-bit Sign-Magnitude
+50101
−51101
+00000
−01000

One's Complement

Negate by flipping all bits. Still has two zeros.

Decimal4-bit One's Complement
+50101
−51010

Two's Complement (standard)

Negate by flipping all bits and adding 1. One representation of zero; used in virtually all modern hardware.

Decimal4-bit Two's Complement
+70111
+10001
00000
−11111
−71001
−81000

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)

73 = 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).

DecimalBCD
00000
50101
91001
250010 0101
991001 1001

BCD is used in financial and display hardware where human-readable digits matter more than compact storage.

Character Encodings

EncodingBitsNotes
ASCII7 (8 w/ parity)128 characters; 'A' = 0x41 = 65
Extended ASCII8256 characters
Unicode (UTF-8)8–32 variableBackward-compatible with ASCII

ASCII layout landmarks:

  • 0x300x39 → digits '0'–'9'
  • 0x410x5A → uppercase 'A'–'Z'
  • 0x610x7A → lowercase 'a'–'z'
  • Lowercase = uppercase + 0x20 (set bit 5)

Powers of 2 Reference

PowerValueCommon name
2¹⁰1 0241 Ki (kibi)
2²⁰1 048 5761 Mi (mebi)
2³⁰1 073 741 8241 Gi (gibi)
2³²4 294 967 2964 G (IPv4 address space)
2⁶⁴≈ 1.84 × 10¹⁹64-bit address space