# Barrel shifter 16-bits (vhdl)

1. Homework Statement
A, and B both are 16 bits wide; A is entity to shift and B is by how much;
we are supposed to implement a BARREL shifter. And here's the explanation (which does not make much sense to me, esp. the example) given in lab document:

A barrel shifter is a combinational logic device that incrementally shifts in stages. In our barrel shifter, we will have 4 stages. Each stage can choose to shift or not to shift, giving any total shift amount. For example, to shift an input by 9, stages one and four will shift 1 time and 8 times, respectively. Stages two and three will not shift. Notice that the binary number 9 is "1001". How convenient that the fourth bit and the first bit are 1 and the second and the third bits are 0.

3. The Attempt at a Solution
ok, I know how to write the shift register, a regular without the "barrel", and after some googling, I found that barrel basically shifts by the amounts of bits specified at once. If someone could explain how the description from the lab document makes sense that is all i need to understand.... thanks in advance.

Related Engineering and Comp Sci Homework Help News on Phys.org
chroot
Staff Emeritus
Gold Member
I presume you have four shifters wired up in series, the output of one connected to the input of the next. Each shifter is also followed by a mux, so that you can bypass each shifter if you do not wish to use it.

The first shifter shifts only one bit position. If the value put into the first shifter is 10010010, you'll get out 00100100.

The second shifter shifts two bit positions. If you put in 10010010, you'll get out 01001000.

The third shifter shifts four bit positions, and the fourth shifter shifts eight bit positions.

By "enabling" some combination of these individual shifters (i.e. by not bypassing them with a mux), any total shift from zero bits to fifteen bits is possible. Note that this device is really nothing more than muxes and wires.

- Warren

Last edited:
ok, that makes a bit more sense....
so, just to make sure, let's say he wants us to shift left by 10, which is "1010" then shifter 2 and 4 are enabled, so I will shift by 2 first and then by 8, right?
So if the input is "1010 0111 0001"
then I will have after shifter 2: "1001 1100 0100"
then after shifter 4: "0100 0000 0000 0000"

edit: one more thing: it seems like I will be able to shift only 15 times is that how it's supposed to work out?:uhh:

thanks sooo much...

Last edited:
mjsd
Homework Helper
that looks correct to me 