Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

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.

Big circuit: pinch, scroll or tap + to zoom in, then drag to move around.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “4-bit bidirectional shift register”, https://digiwleea.wleeaf.dev/tools/build/bidirectional-shift-register/

What you need

Step by step

  1. Place a clock CLK, inputs DIR and DIN, and four D flip-flops on the same clock, with probes Q3 to Q0.
  2. 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.
  3. 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.
  4. 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 edgeDIRDirectionDINQ3 Q2 Q1 Q0
10right11???
20right111??
30right0011?
40right11011
50right00101
60right00010
71left10101
81left01010
91left10101
101left11011
110right00101
120right11010

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.