Skip to content
BetterDL

Shift left

Also called: left shift, logical shift left, arithmetic shift left, LSL, SHL, SLL, ASL

Moving every bit one place toward the MSB, with a 0 entering at the LSB. It multiplies the value by 2 as long as no significant bit falls off.

A shift left moves every bit one place toward the MSB. In this course's notation (Q3 Q2 Q1 Q0), bits move toward Q3, the serial input enters Q0, and the old Q3 drops out. Wiring: D0 = SI, D1 = Q0, D2 = Q1, D3 = Q2.

For arithmetic, a 0 enters on the right. Each bit moves to a position worth twice as much, so the value doubles:

00000101 (5) → 00001010 (10) → 00010100 (20).

Shifting left k places multiplies by 2ᵏ.

When it goes wrong: if a 1 is shifted out of an unsigned register, the result is too big to fit, which is overflow. For a two's complement value, the result is wrong if the sign bit changes. For example, 01011000 (+88) shifted left gives 10110000, which reads as −80.

The same operation serves signed and unsigned numbers, which is why "logical shift left" and "arithmetic shift left" are the same thing. Only right shifts come in two flavors (logical shift right and arithmetic shift right).

Why it matters: shifts are far cheaper than multipliers. Compilers turn x × 8 into a shift by 3, and x × 10 into (x shifted left 3) + (x shifted left 1).

0
128
0
64
0
32
0
16
0
8
1
4
0
2
1
1

Worked examples

Example

Multiplying by 4

An 8-bit unsigned register holds 00000011 (3). Shift it left twice, with 0s entering.

  1. 1.

    First shift: 00000110 = 6.

  2. 2.

    Second shift: 00001100 = 12.

  3. 3.

    3 × 2² = 12. ✓

Example

Overflow and negative numbers

Shift the 4-bit unsigned value 1011 (11) left once, then the 8-bit two's complement value 11111010 (−6) left once.

  1. 1.

    1011 → 0110. A 1 fell off the left end, so the result 6 is wrong: 22 does not fit in 4 bits. Overflow.

  2. 2.

    11111010 → 11110100. The sign bit stayed 1.

  3. 3.

    11110100 = −128 + 64 + 32 + 16 + 4 = −12 = −6 × 2. ✓

Common mistakes

  • Putting the serial input in Q3. For a shift left it enters Q0.

  • Ignoring the bit that falls off. If it is a 1 (unsigned) the product has overflowed.

  • Thinking a left shift needs a special signed version. Shifting in 0 works for two's complement too, as long as the sign does not change.

Practice Shift left

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Shift left is taught in Registers and Adders and ALUs.