Bidirectional shift register: shift left or right, live
A bidirectional shift register moves its stored bits one place left or right on every clock edge, as chosen by a direction input. In this 4-bit one, DIR = 0 shifts right (DIN enters at Q3 and the bits move toward Q0) and DIR = 1 shifts left (DIN enters at Q0 and the bits move toward Q3).
It is a plain shift register with a 2-to-1 multiplexer in front of every flip-flop. Each flip-flop has two possible sources, its left neighbor and its right neighbor, and DIR picks one: D = (DIR AND left source) OR (NOT DIR AND right source). At the two ends the missing neighbor is replaced by the serial input DIN, so the same pin feeds Q3 when shifting right and Q0 when shifting left. Shifting a binary number left by one place doubles it and shifting it right halves it, which is why processors use shifts for fast multiplication and division by 2. Add a hold mode and a parallel load and you have the universal shift register of the 74194 chip; the bitwise calculator shows the same shifts on whole numbers.
Open this circuit in the lab →
What you need
- 4× D flip-flop: one per bit, all on the same clock
- 4× AND: left-shift path: DIR AND the neighbor below (DIN for Q0)
- 4× AND: right-shift path: NOT DIR AND the neighbor above (DIN for Q3)
- 4× OR: join the two paths into each D input
- 1× NOT: NOT DIR, shared by all four bits
Step by step
- Place a clock
CLK, inputsDIRandDIN, and four D flip-flops on the same clock, with probesQ3toQ0. - For each bit, AND its lower neighbor's Q with DIR (for Q0, AND DIN with DIR): that is the bit it takes when shifting left.
- AND its upper neighbor's Q with NOT DIR (for Q3, AND DIN with NOT DIR): that is the bit it takes when shifting right.
- OR the two into the flip-flop's D input. Set DIR, set DIN, and watch the pattern slide one place per clock.
Shift sequence
| Clock edge | DIR | Direction | DIN | Q3 Q2 Q1 Q0 |
|---|---|---|---|---|
| 1 | 0 | right | 1 | 1??? |
| 2 | 0 | right | 1 | 11?? |
| 3 | 0 | right | 0 | 011? |
| 4 | 0 | right | 1 | 1011 |
| 5 | 0 | right | 0 | 0101 |
| 6 | 0 | right | 0 | 0010 |
| 7 | 1 | left | 1 | 0101 |
| 8 | 1 | left | 0 | 1010 |
| 9 | 1 | left | 1 | 0101 |
| 10 | 1 | left | 1 | 1011 |
| 11 | 0 | right | 0 | 0101 |
| 12 | 0 | right | 1 | 1010 |
This is the exact run checked before the page is built, on all four outputs after each of the 12 clocks (? is a bit not yet filled since power-on, which the check skips). Four right shifts load 1011 one bit at a time from the top, two more push it down, four left shifts bring new bits in at Q0, and two right shifts turn back.
You can also read the full theory in the lesson on shift registers. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Registers and counters
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the 4-bit bidirectional shift register in the lab →Frequently asked
What is a bidirectional shift register?
A shift register that can move its bits either left or right on each clock edge, chosen by a direction input. Each flip-flop takes its value from one neighbor or the other through a 2-to-1 multiplexer.
What is the difference between a bidirectional and a universal shift register?
A bidirectional shift register shifts left or right. A universal shift register can also hold its value and load all bits in parallel, usually chosen by two mode inputs, as in the 74194.
Why shift left or right?
Shifting a binary number left one place multiplies it by 2 and shifting right divides it by 2 (dropping the remainder), so shifts are a cheap way to scale numbers. They also move data serially, one bit per clock, over a single wire.
How many multiplexers does a 4-bit bidirectional shift register need?
One 2-to-1 multiplexer per bit, so four, each built here from two AND gates and an OR gate, plus one shared NOT for the direction input.