Electronic – How do bitshifts work on the electrical layer

alubinarydigital-logic

I'm a software developer and I understand how arithmetic and logical bitshifts work in principle.

But how do they work on the electrical layer?

I might have a completely wrong imagination;

Let's say we have the binary value 0000 1011 and left shift it by 2.
The outcome is 0010 1100, nothing special.

But how do the bits "jump" to their second neighbors?

Edit: Fixed a slip, where I wrote "right shift" while doing a left shift.

Edit: Added ALU and DIGITAL-LOGIC tags

Best Answer

In computers, arithmetic operations are performed by a specific integrated circuit that is placed inside the microprocessor, and is called "Arithmetic Logic Unit". You can have a look at the Wikipedia article on ALU ( https://en.wikipedia.org/wiki/Arithmetic_logic_unit ). As an example it mentions the 74181 ALU, which is a very simple Arithmetic logic unit, able to perform several types of operations, including the left shift, over 4 bits.

I've attached the logic schema of the 74181 ALU (see below). Inputs are A and B, and result is F. Each number is 4 bits long, so there is A3A2A1A0, B3B2B1B0, and F3F2F1F0. The desired operation is selected with S3S2S1S0:

  • F = A (op) B
  • 'op' is the desired operation.
  • If S = S3S2S1S0 = 1100, then 'op' is left shifting.

This is how left shifting works in the particular case of the 74181:

  • Look at the upper left group of five AND gates and 2 NOR gates.
  • First AND gate is not exactly AND, because it has only one entry: /A0. Therefore its output is /A0.
  • Second and third AND gates have 0 output because S1S0 = 00
  • Fourth AND gate has output /A0*B0, because S2 = 1
  • Fifth AND gate has output /A0*/B0, because S3 = 1
  • First NOR gate has output A0.
  • Second NOR gate has output A0, because /A0*B0 + /A0*/B0 = /A0.

In conclusion, when you have S3S2S1S0 = 1100, the ALU makes F = A + A, which is the same as left shifting.

Simplified schema of the 74181 ALU