Barrel shifters
A barrel shifter is a combinational circuit that shifts (or rotates) a data word by any number of bit positions in one clock cycle, using only multiplexers — no clocking, no iteration.
The Core Idea
WHY do we need it?
Processors execute instructions like SHL R1, 5 or floating-point normalisation, address scaling, and multiply/divide-by-powers-of-2 — every cycle. A multi-cycle shifter would stall the pipeline. We want a single-cycle, purely combinational device.
WHAT is it, precisely?
HOW is it structured?
The key insight: decompose the shift amount into bits.
- Stage is controlled by bit .
- If , stage shifts its input by ; if , it passes data through unchanged.
- Cascade all stages → total shift . ✅

Deriving the multiplexer equation from scratch
Consider stage , which shifts left by when (fill with 0s). Let the stage input be and output .
What does "left shift by " mean? Output bit takes input bit :
When , pass through: .
Combine both cases with a 2:1 mux selected by :
For a rotate, the bits that fall off the end wrap around instead of being replaced by 0:
Counting the hardware (the 80/20 that matters)
- Number of stages .
- Each stage has muxes (one per output bit).
- Total muxes .
- Propagation delay — grows only logarithmically, which is why it's fast.
Worked Example 1 — Shift left by 13 on an 8… wait, 16-bit word
Take , so stages (shift by 1, 2, 4, 8). Shift amount .
Step 1 — write in binary. , so . Why? The control bits ARE the binary digits of the shift amount.
Step 2 — turn on the matching stages.
- → shift by
- → pass through
- → shift by
- → shift by
Step 3 — total shift . ✅ Why this step? Confirms the sum-of-powers decomposition equals the requested shift.
Trace with input A = 0000 0000 0000 0001 (value 1):
- After stage 0 (shift 1):
...0010 - Stage 1 (pass):
...0010 - Stage 2 (shift 4):
...0010 0000 - Stage 3 (shift 8):
0010 0000 0000 0000= . ✅ (.)
Worked Example 2 — Rotate right by 3 on a 4-bit word
, stages. Rotate-right amount , so : rotate by 1 then by 2.
Input (bit 3 set).
- Rotate right by 1 →
0100Why? ; bit that leaves bottom wraps to top. - Rotate right by 2 →
0001Why? Applying the mod-wrap again by .
Total rotate-right by 3 of 1000 = 0001. Check directly: rotating 1000 right 3 = 0001. ✅
Common Mistakes
Active Recall
Recall Q: Why only
stages? Because the shift amount (0…) is a -bit binary number; each bit selects a stage that shifts by that power of two, and their sum reproduces any amount.
Recall Q: Write the per-bit mux equation for a left-shift stage
. (with ).
Recall Q: Mux count and delay for
? Muxes ; delay mux delays.
Recall Feynman: explain to a 12-year-old
Imagine you want to move a row of books along a shelf by any number of spaces, but you're only allowed to push them in jumps of 1, 2, 4, or 8. To move them 13 spaces, you do jumps of 8, then 4, then 1 (that's 13!). Each jump is a separate "helper" you can switch ON or OFF. With just 4 helpers you can slide the books by any amount from 0 to 15 in one go, instead of nudging them one space at a time. That's a barrel shifter — a stack of ON/OFF sliders, one for each power of two.
Connections
- Multiplexers — the fundamental building block (2:1 mux per bit).
- Binary Number Representation — decomposition of shift amount into powers of two.
- Combinational Circuits — no clock, purely input-driven.
- Shift and Rotate Operations — the ALU operations this implements.
- Logarithmic Delay Structures — same idea as carry-lookahead / prefix networks.
- Floating Point Normalization — a major real user of fast shifters.
What is a barrel shifter?
How many stages does an n-bit barrel shifter have?
How many 2:1 muxes total?
What is the propagation delay in terms of mux delays?
Per-bit equation of a left-shift stage i?
How wide is the shift-amount control input?
Which stages are active to shift by 13?
Difference between shift and rotate stage inputs?
Why powers of two per stage instead of 1 each?
Rotate-right-by-3 of 1000 (4-bit)?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, barrel shifter ka basic idea bahut simple hai. Maan lo tumhe ek number ko 13 positions left shift karna hai. Agar tum ek baar mein sirf 1 bit shift kar sakte ho, to 13 clock cycles lag jaayenge — bahut slow! Iska smart solution: shift amount ko binary mein todo. , matlab . Ab agar tumhare paas alag-alag "stages" hain jo fixed jumps de sakte hain — koi stage 1 ka jump, koi 2 ka, koi 4 ka, koi 8 ka — to bas jo stages chahiye unhe ON kar do, baaki OFF. Sab ek hi cycle mein ho jaata hai, no clock, pura combinational.
Har stage sirf 2-to-1 multiplexers ki ek row hoti hai. Har mux decide karta hai: "main apna original bit pass karoon ya shifted bit?" Control bit jab 1 hoga to shifted version aayega, jab 0 hoga to seedha pass ho jaayega. Equation yaad rakho: — yahi to ek mux hai! Isliye humein koi naya formula ratna nahi padta, mux se hi derive ho jaata hai.
Sabse important baat jo exam mein poochte hain: -bit shifter ke liye stages , total muxes , aur delay bhi hi. Yeh log wala jaadu isliye kaam karta hai kyunki koi bhi shift amount powers of two ka sum hota hai — jaise binary representation. Isliye 32-bit ke liye sirf 5 stages, 160 muxes.
Ek galti se bachna: shift aur rotate mein farak hai. Logical shift mein jo bits bahar jaate hain unki jagah 0 aata hai; rotate mein woh bits wapas doosre end pe aa jaate hain (wrap around, ). Structure same, bas mux ka doosra input alag. Yeh chhoti si baat exam mein marks dilaati hai!