Half Adder, Full Adder, and Subtractors: Design and Working
Overview: Add the binary digits 1, 1 and an incoming carry of 1.
What are Adders and Subtractors?
- Inside the CPU, addition is the foundation of all calculations.
- If a computer can add, it can also subtract (using 2’s complement).
- It can multiply (by repeated addition).
- It can divide (by repeated subtraction).
- An everyday example
- When you add numbers by hand on paper (like
28 + 15): - First you add
8 + 5 = 13. - Then in the next column, you must add
2 + 1plus that carried-over 1!
Half Adder
- A Half Adder is a combinational circuit that adds two single-bit binary numbers (
AandB). - It produces two outputs: Sum (S) and Carry (C).
- 0: 0
- 0: 1
- 1: 0
- 1: 1
- Boolean Expressions: Sum (S):
S = A'B + AB'= A ⊕ B (Built using an XOR Gate) - Carry (C):
C =A • B (Built using an AND Gate)
View diagram · Half Adder Logic Circuit
Full Adder
- A Full Adder fixes the limitation of the Half Adder.
- It adds three 1-bit binary inputs: two main bits (
A,B) and a previous carry bit (Cin). - It produces two outputs: Sum (S) and Carry Out (Cout).
- 0: 0
- 0: 0
- 0: 1
- 0: 1
- 1: 0
Half Subtractor
- A Half Subtractor subtracts one bit from another (
A - B). - Outputs: Difference (D) and Borrow (Bout).
- 0: 0
- 0: 1
- 1: 0
- 1: 1
- Boolean Expressions: Difference (D):
D = A'B + AB'= A ⊕ B - Borrow (Bout): Bout = A’ • B (Needs a NOT gate on A, followed by an AND gate)
Full Subtractor
- A Full Subtractor subtracts three 1-bit inputs:
- First number (A), subtracted number (B), and a previous borrow (Bin).
- Outputs: Difference (D) and Borrow Out (Bout).
- 0: 0
- 0: 0
- 0: 1
- 0: 1
- 1: 0
Multiplexers, Demultiplexers, Encoders, and Decoders
Overview: A four-to-one multiplexer uses two select bits to choose one of four inputs.
Overview: Digital Traffic Directors in Computers
- Inside a computer, many devices (CPU, RAM, Hard Disk, Graphics Card) must share common data wires.
- If all devices sent signals at the exact same moment, data would collide and get ruined!
- To prevent this, computer hardware uses Multiplexers, Demultiplexers, Decoders, and Encoders to manage traffic smoothly.
- Multiplexer (MUX) 2ⁿ → 1 (Data Selector) Takes many input lines and connects only one to the output line.
- Demultiplexer (DEMUX) 1 → 2ⁿ (Data Distributor) Takes one input line and routes it to one of many output lines.
View diagram · Data Routing Circuits at a Glance
Multiplexer (MUX) — The Data Selector
- A Multiplexer has:
2ⁿdata input linesnselect control lines- Only 1 output line
- An everyday example
- Think of a railway junction outside a busy railway station.
- 4 train tracks merge down into 1 single platform track.
- The signal operator sets the track switch to let only one train enter the platform at a time.
Demultiplexer (DEMUX) — The Data Distributor
- A Demultiplexer does the exact opposite of a MUX:
- Has 1 data input line (Din)
- Has
nselect lines - Has
2ⁿoutput lines - 1-to-4 Demultiplexer: Select lines
S₁, S₀steer the inputDinto one specific output line (Y₀, Y₁, Y₂, Y₃). - Boolean Expressions:
Y₀ = S₁'S₀' • Din Y₁ = S₁'S₀ • DinY₂ = S₁S₀' • Din
Decoders (e.g., 3-to-8 Line Decoder)
- A Decoder takes an
n-bit binary code and turns ON exactly one of its2ⁿoutput lines. - An everyday example
- When the professor calls out Roll Number
15in the classroom, only one student raises their hand and stands up. - Where is a Decoder Used?: RAM Memory Addressing: The CPU sends a binary address (e.g.,
101), and the decoder turns ON that exact memory cell to read or write data. - 7-Segment Display: Translates binary numbers to light up digits on a microwave or calculator screen.
- 3-to-8 Decoder Operation: Inputs: 3 binary lines (
A, B, C) and 1 Enable pin (E). - Outputs: 8 lines (
Y₀toY₇). - If
E = 0: The decoder is OFF; all outputs stay 0.
Encoders and Priority Encoders
- An Encoder does the reverse of a decoder:
- It takes
2ⁿinput lines (where only one line is pressed or active) and outputs the matchingn-bit binary number. - Example: When you press button
7on a numeric keypad, the encoder converts it to0111. - What is a Priority Encoder?: In a basic encoder, if you press two buttons at once, the output becomes corrupted garbage.
- A Priority Encoder fixes this by assigning importance to each line.
- If multiple inputs are HIGH at the same time, it picks the highest priority input and ignores the lower ones!
- Use: Crucial for CPU Interrupts (e.g., Power Failure signal takes priority over a mouse click).
Flip-Flops: SR, D, JK, Master-Slave JK, and T Flip-Flop
Overview: Use a D flip-flop to store one attendance flag on a clock edge.
What is a Flip-Flop?
- A Flip-Flop is the smallest memory cell in computer hardware.
- It can store exactly one binary bit (either a 0 or a 1).
- It holds this bit safely as long as the computer is turned ON.
- Unlike logic gates that calculate and forget, a flip-flop remembers its value until a clock pulse tells it to change!
- An everyday example
- Think of a classroom wall switch.
- If you press it down, the light stays ON even after you take your finger away.
- It remembers its state until someone physically presses it back up!
View diagram · Latch vs. Flip-Flop Distinction
SR (Set-Reset) Flip-Flop
- The SR Flip-Flop has two control inputs:
- S (Set): Makes output
1. - R (Reset): Clears output to
0. - CLK (Clock): Tells the circuit when to update.
- ↑: 0
- ↑: 0
- ↑: 1
- ↑: 1
D (Data / Delay) Flip-Flop
- The D Flip-Flop solves the SR forbidden problem completely.
- It has only one data input: D.
- Whatever bit is present at D is safely copied into memory on the next clock tick!
- ↑: 0
- ↑: 1
- Characteristic Equation: Q(next) = D
- Where is it used? D flip-flops are used in CPU registers, RAM memory cells, and cache memory.
JK Flip-Flop (The Universal Flip-Flop)
- The JK Flip-Flop fixes the forbidden condition of the SR flip-flop.
- J works like Set (
1). - K works like Reset (
0). - When both
J = 1andK = 1, it toggles (flips the previous bit: 0 becomes 1, and 1 becomes 0). - ↑: 0
- ↑: 0
- ↑: 1
- ↑: 1
T (Toggle) Flip-Flop
- The T Flip-Flop is made by joining inputs J and K together into one single wire called T.
- If
T = 0: It keeps the previous value (No change). - If
T = 1: It inverts the previous value (Toggle: 0 becomes 1, 1 becomes 0). - ↑: 0
- ↑: 1
- Characteristic Equation: Q(next) = T ⊕ Q
- Where is it used? T flip-flops are the building blocks of digital counters and digital clocks.
Quick Excitation Table
- When designing counters, you need to know what inputs to apply to jump from current state
Qto next stateQ_next: - 0 → 0:
0 X - 0 → 1:
1 0 - 1 → 0:
0 1 - 1 → 1:
X 0
Registers, Shift Registers, and Bidirectional Shift Registers with Parallel Load
Overview: Load 1010 into a four-bit register.
What is a Register?
- A single flip-flop can store only 1 bit (
0or1). - But computers process data in groups: bytes (8 bits) or words (16, 32, or 64 bits).
- A Register is simply a group of flip-flops working together to store multi-bit binary numbers.
- For example, a 4-bit register has 4 flip-flops and can store any number from 0 to 15.
- An everyday example
- Think of a classroom bench.
- One individual chair holds only 1 student (like a single flip-flop).
- A 4-seater bench holds 4 students seated side-by-side (like a 4-bit register)!
4-Bit Register with Parallel Load
- In a normal register, every clock tick might overwrite the stored data.
- But the CPU doesn’t want to change data on every tick!
- It only wants to load new data when a command signal called LOAD is turned ON (
LOAD = 1). - How It Is Built: Uses four D flip-flops (
FF₀toFF₃). - Each flip-flop has a 2-to-1 Multiplexer in front of its input.
- When LOAD = 0: The old stored bit loops back to input
D. - When LOAD = 1: The external input bits (
I₀, I₁, I₂, I₃) pass through toD. - A common Clear line resets all flip-flops to
0000whenever needed.
View diagram · 4-Bit Parallel Load Register Architecture
Four Modes of Shift Registers
- A Shift Register can slide its stored bits one step to the left or right with every clock pulse.
- 1. SISO Serial-In Serial-Out Data enters bit-by-bit and leaves bit-by-bit.
- 2. SIPO Serial-In Parallel-Out Data enters bit-by-bit and reads out all at once.
- 3. PISO Parallel-In Serial-Out Data loads all at once and transmits one bit at a time.
- 4. PIPO Parallel-In Parallel-Out Loads all at once and outputs all at once.
View diagram · The Four Shift Register Configurations
Bidirectional Shift Register with Parallel Load
- A Bidirectional Shift Register (also called a Universal Shift Register) can do all operations in one chip:
- Shift Right: Slides bits to the right (This divides a binary number by 2!).
- Shift Left: Slides bits to the left (This multiplies a binary number by 2!).
- Parallel Load: Loads all bits at once.
- Hold (No Change): Keeps current data untouched.
- 0: 0
- 0: 1
- 1: 0
4-Bit Synchronous and Asynchronous (Ripple) Binary Counters
Overview: A three-bit binary counter passes through eight states before repeating.
What is a Digital Counter?
- A Counter is a sequential circuit that counts clock pulses.
- Every time a clock pulse arrives, the stored binary number goes up by 1:
- An everyday example
- Think of a digital token display at a railway ticket counter or bank counter.
- Every time the clerk presses the button, the token number advances by 1.
- Inside the CPU, the Program Counter (PC) does this exact counting to step through instructions line by line!
- Asynchronous (Ripple) Counters
- Synchronous Counters
4-Bit Asynchronous (Ripple) Binary Counter
- In an Asynchronous Counter, the flip-flops are not clocked together.
- The external clock wire is connected only to the first flip-flop (FF₀).
- The output of FF₀ acts as the clock for FF₁!
- The output of FF₁ acts as the clock for FF₂!
- The signal travels like a water ripple or a falling line of dominoes.
- How It Works: Built using four T or JK flip-flops locked in Toggle mode (
T = 1orJ = K = 1). - Each flip-flop divides the frequency by 2.
- The Major Problem (Cumulative Delay):
View diagram · Asynchronous Ripple Cascade
4-Bit Synchronous Binary Counter
- In a Synchronous Counter, the common clock wire is connected to every flip-flop simultaneously.
- When a clock pulse arrives, all flip-flops update at the exact same instant!
- There is no domino delay.
- How Each Flip-Flop Decides to Toggle (Using T Flip-Flops): Look at regular binary counting:
- FF₀ (LSB): Flips on every single clock tick:
- FF₁: Flips only when Q₀ is 1:
- FF₂: Flips only when both Q₀ and Q₁ are 1:
- FF₃ (MSB): Flips only when Q₀, Q₁, and Q₂ are all 1:
Comparison: Synchronous vs. Asynchronous Counters
- Clock Connection: Clock goes only to 1st flip-flop; others get clock from previous output
- Trigger Timing: One after another (domino effect)
- Speed: Slow (total delay =
n × delay) - Circuit Simplicity: Very simple (no extra AND gates)
- Glitches / Errors: High chance of momentary wrong numbers
- Cost: Cheaper