3B Infrastructure home

All subjects

Digital Fundamentals

How computers work at the lowest level: binary numbers, logic gates, and circuits that remember. Press play on any sketch to watch it happen.

1 Binary and number systems

Computers store everything as bits, because a circuit can reliably be on or off. Each binary digit is worth double the one to its right, just as each decimal digit is worth ten times.

  • Bit and byte: a bit is 0 or 1, and a byte is 8 bits.
  • Hexadecimal: one hex digit stands for 4 bits, so 1101 is D.
  • Two's complement: the standard way to store negative numbers: flip the bits, then add 1.
  • Overflow: an 8-bit unsigned value holds 0 to 255. 255 + 1 wraps round to 0.
1101₂ = 8 + 4 + 0 + 1 = 13
13    = 0x0D

 5 = 0000 0101
-5 = 1111 1011   flip, then add 1

Worked example

8s14s?2s?1s?Total = 8

1/4 Read 1101 from the left. The 8s bit is on.

Rule of thumb: Learn the powers of two up to 1024 by heart. They appear everywhere in computing.

2 Logic gates and adders

Gates are tiny circuits that make decisions from bits. Combine a few and you can add numbers, which is the first step towards a full processor.

  • AND: output is 1 only if both inputs are 1.
  • OR: output is 1 if any input is 1.
  • XOR: output is 1 if the inputs differ.
  • NOT: flips the input.
  • Half adder: XOR gives the sum bit, and AND gives the carry.

Logic diagram

A = 0B = 0XORANDSum = 0Carry = 0

1/4 0 + 0: nothing is on, so both outputs stay 0.

ABSumCarry
0000
0110
1010
1101

Rule of thumb: Truth tables never lie. When a circuit confuses you, write one out.

3 Flip-flops and counters

Logic gates alone forget everything. A flip-flop stores one bit, and it updates only on a clock edge. Group them and you get registers, counters and memory.

  • Clock: a steady signal that tells the whole circuit when to change.
  • D flip-flop: copies D to Q on the rising clock edge, then holds it.
  • Register: a group of flip-flops that stores a number.
  • Counter: a register that adds one on each clock tick.

Timing diagram

D = 1Clock lowD flip-flopQ = 0

1/4 D changes to 1, but the clock is low, so Q ignores it.

Rule of thumb: Combinational logic works out the next value. Flip-flops decide when it takes effect.