3.3.11 · D1Combinational Circuits

Foundations — Barrel shifters

1,975 words9 min readBack to topic

Before we can even read the parent note, we must earn every symbol it throws at us: bits, indices, powers of two, binary, , the mux equation, and the little sign. This page builds each one from the ground, in an order where nothing appears before it is defined.


1. A bit, and a word of bits

Picture a row of light switches. Each switch is either OFF () or ON (). Put of them in a line and you have a word — the thing a shifter shifts.

Why does the topic need this? A barrel shifter takes a word in and gives a word out. If we don't nail down "what is a word," every later sentence is unreadable.


2. The index and the position of a bit

Each switch in the row needs a name so we can talk about "the third one." That name is its index.

Why count from the right and start at ? Look at the next section: the value of a bit depends on , and starting at makes the rightmost bit worth . It lines up the picture with the arithmetic.


3. Powers of two,

The whole trick of a barrel shifter is powers of two, so let's make sure that notation is solid.

Picture doubling: start with 1 domino, double to 2, double to 4, double to 8. Each step is ; after steps you have .


4. Binary — writing numbers as sums of powers of two

Take . Ask: which powers of two add up to ? Include ; skip . Reading the switches from down to : . So (the small means "read this as binary").

The tall ("sigma") is just shorthand for "add all of these up." The label underneath is the starting index; the on top is the last. This is why the parent can say "shift-by-13 = shift-by-8 + shift-by-4 + shift-by-1" — that sentence IS the binary expansion of .

See Binary Number Representation for the full rules of this number system.


5. The logarithm — how many switches do we need?

We have powers of two () as our building blocks. Question: to build any amount from up to , how many of these blocks (switches) do we need?

Picture climbing the doubling ladder from the previous figure: is 4 rungs, so .


6. The multiplexer — the single Lego brick

Every stage is built from one repeated part: the multiplexer. Full detail lives in Multiplexers; here is the minimum you need.

Now three tiny logic symbols so the mux equation reads cleanly:

Put them together and the mux is a one-line formula: Read it: "if then so the first term is and the second term is — output is . If , the second term wins — output is ." That is a mux, derived, not assumed. Every per-bit stage equation in the parent note is just this formula with and the shifted bit.


7. Shift versus rotate, and the sign

When bits slide sideways, some fall off the edge. What replaces them?

To say "wrap around" in math we need one more symbol:

See the Hinglish companion if you'd like these ideas restated in mixed Hindi-English.


8. How the pieces feed the topic

Bit 0 or 1

n-bit word A

Bit index j from 0

Powers of two 2 to the i

Binary sum of powers

Shift and rotate meaning

log base 2 of n stages

AND OR NOT gates

2 to 1 multiplexer

One shifter stage

mod n wrap around

Barrel shifter 3.3.11

Every arrow says "you must understand the tail before the head makes sense." Follow them left-to-right and the parent note reads like plain English.


Equipment checklist

Cover the right side and answer aloud. If any stumps you, re-read its section above.

What a bit is
A single cell holding either or .
How bit indices are counted
From the right, starting at ; bit has weight .
What means and the first five values
Two multiplied by itself times: .
How to write in binary and why
; it's the sum of distinct powers of two.
What answers
How many doublings from reach = how many binary digits / stages needed.
Why (ceiling) appears
You can't build a fractional stage, so round the bit-count up.
The 2:1 mux equation
.
Meaning of , , in Boolean form
NOT (flip), AND (both), OR (at least one).
Difference between shift and rotate
Shift fills vacated bits with ; rotate wraps them via .
What computes
The remainder after dividing by — clock-style wrap-around.

Connections

  • Multiplexers — the 2:1 mux brick every stage is made of.
  • Binary Number Representation — the sum-of-powers-of-two decomposition.
  • Combinational Circuits — the AND/OR/NOT gate world these live in.
  • Shift and Rotate Operations — the two edge behaviours defined here.
  • Logarithmic Delay Structures — why growth is the whole point.
  • Floating Point Normalization — a real consumer of fast shifting.