A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Barrel Shifter and Rotation Circuits

College Depth 78 in the knowledge graph ☐ I know this ☆ Set as goal
327prerequisites beneath it
See this on the map →
Multiplexers and DemultiplexersCombinational Circuit Design→
shifter rotation barrel-shifter

Core Idea

A barrel shifter performs multi-position shifts or rotations in a single clock cycle using cascaded multiplexers. Unlike a serial shifter that requires multiple cycles, a barrel shifter can shift by any amount (even 0) in parallel. Rotations are used in cryptographic algorithms and bit manipulation.

Explainer

From your work with multiplexer circuits, you know that a mux selects one of several inputs based on a control signal. A barrel shifter is built entirely from multiplexers arranged in a clever pattern that decomposes an arbitrary shift into a sequence of power-of-two shifts, each handled by one layer of muxes — all operating in a single clock cycle with no feedback or sequential logic required.

Consider an 8-bit barrel shifter that must shift its input by any amount from 0 to 7 positions. The shift amount is a 3-bit binary number (e.g., shift by 5 = binary 101). The barrel shifter uses three stages, one for each bit of the shift amount. The first stage either shifts by 4 positions or passes the data through, controlled by bit 2 of the shift amount. The second stage either shifts by 2 or passes through, controlled by bit 1. The third stage either shifts by 1 or passes through, controlled by bit 0. A shift by 5 (101) activates the 4-shift stage and the 1-shift stage, producing a net shift of 5. Each stage is simply a row of 2-to-1 multiplexers — one per bit of the data word — where each mux chooses between the unshifted input and the shifted input for that stage.

This logarithmic decomposition is what makes barrel shifters fast. An n-bit shifter needs only log₂(n) stages, each adding one mux delay. A 32-bit barrel shifter uses 5 stages; a 64-bit shifter uses 6. The total delay is proportional to log₂(n) multiplexer delays rather than n clock cycles as a serial shift register would require. The tradeoff is area: the barrel shifter uses n × log₂(n) multiplexers, which is substantially more hardware than a simple shift register. But in a processor where shift and rotate instructions must complete in a single cycle, this area cost is well worth the speed.

The same structure supports logical shifts (fill vacated positions with zeros), arithmetic shifts (fill with the sign bit to preserve the sign of a two's complement number), and rotations (bits shifted out one end re-enter at the other). The difference is only in what value the multiplexers select for the vacated bit positions. For a logical left shift, zeros fill in from the right. For an arithmetic right shift, the sign bit (MSB) fills in from the left. For a rotation, the bits that would be shifted out wrap around to the opposite end. A single barrel shifter circuit with a few extra control signals can perform all these operations, which is why processors typically implement shifts and rotates with one shared barrel shifter inside the ALU rather than building separate circuits for each operation.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Multiplexers and Demultiplexers → Barrel Shifter and Rotation Circuits

Longest path: 79 steps · 327 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.