Barrel shifters
3.3.11· Hardware › Combinational Circuits
A barrel shifter ek combinational circuit hai jo ek data word ko ek hi clock cycle mein kisi bhi number of bit positions se shift (ya rotate) karta hai — sirf multiplexers use karke — koi clocking nahi, koi iteration nahi.
The Core Idea
WHY do we need it?
Processors SHL R1, 5 ya floating-point normalisation, address scaling, aur multiply/divide-by-powers-of-2 jaise instructions har cycle execute karte hain. Ek multi-cycle shifter pipeline ko stall kar deta. Hum chahte hain ek single-cycle, purely combinational device.
WHAT is it, precisely?
HOW is it structured?
Key insight: shift amount ko bits mein decompose karo.
- Stage bit se control hota hai.
- Agar , toh stage apna input se shift karta hai; agar , toh data ko unchanged pass karta hai.
- Saare stages cascade karo → total shift . ✅

Deriving the multiplexer equation from scratch
Stage consider karo, jo hone par left mein se shift karta hai (0s se fill karta hai). Stage input aur output maano.
"Left shift by " ka matlab kya hai? Output bit , input bit leta hai:
Jab , pass through karo: .
Dono cases ko se select hone wale 2:1 mux ke saath combine karo:
For a rotate, jo bits end se bahar girti hain woh 0 se replace hone ki jagah wrap around ho jaati hain:
Counting the hardware (the 80/20 that matters)
- Number of stages .
- Har stage mein muxes hote hain (har output bit ke liye ek).
- Total muxes .
- Propagation delay — sirf logarithmically badhta hai, isliye yeh fast hai.
Worked Example 1 — Shift left by 13 on an 8… wait, 16-bit word
lo, toh stages (shift by 1, 2, 4, 8). Shift amount .
Step 1 — ko binary mein likho. , toh . Kyun? Control bits shift amount ke binary digits HAIN.
Step 2 — matching stages ko ON karo.
- → shift by
- → pass through
- → shift by
- → shift by
Step 3 — total shift . ✅ Yeh step kyun? Confirm karta hai ki sum-of-powers decomposition requested shift ke barabar hai.
Input ke saath trace karo 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 , toh : pehle 1 se rotate phir 2 se.
Input (bit 3 set).
- Rotate right by 1 →
0100Kyun? ; jo bit neeche se bahar jaati hai woh upar wrap ho jaati hai. - Rotate right by 2 →
0001Kyun? Mod-wrap dobara se apply karna.
Total rotate-right by 3 of 1000 = 0001. Seedha check karo: 1000 ko right 3 rotate karna = 0001. ✅
Common Mistakes
Active Recall
Recall Q: Sirf
stages kyun? Kyunki shift amount (0…) ek -bit binary number hai; har bit ek aisa stage select karta hai jo us power of two se shift karta hai, aur unka sum koi bhi amount reproduce kar deta hai.
Recall Q: Left-shift stage
ke liye per-bit mux equation likho. (with ).
Recall Q:
ke liye mux count aur delay? Muxes ; delay mux delays.
Recall Feynman: ek 12-saal ke bacche ko explain karo
Socho tum ek shelf par kitabon ki row ko kisi bhi number of spaces se move karna chahte ho, lekin tumhe sirf 1, 2, 4, ya 8 ke jumps mein push karne ki permission hai. Unhe 13 spaces move karne ke liye, tum 8 ka jump karte ho, phir 4 ka, phir 1 ka (total 13!). Har jump ek alag "helper" hai jise tum ON ya OFF kar sakte ho. Sirf 4 helpers se tum kitabon ko 0 se 15 tak kisi bhi amount se ek saath slide kar sakte ho, ek ek space nudge karne ki jagah. Yahi barrel shifter hai — ON/OFF sliders ka ek stack, har power of two ke liye ek.
Connections
- Multiplexers — fundamental building block (2:1 mux per bit).
- Binary Number Representation — shift amount ka powers of two mein decomposition.
- Combinational Circuits — koi clock nahi, purely input-driven.
- Shift and Rotate Operations — ALU operations jo yeh implement karta hai.
- Logarithmic Delay Structures — carry-lookahead / prefix networks jaisa hi idea.
- Floating Point Normalization — fast shifters ka ek major real user.