Skip to content
BetterDL

Logical shift right

Also called: LSR, SRL, logical right shift, unsigned shift right, logical shift

A right shift that fills the vacated MSB with 0. For an unsigned number it divides by 2, rounding down; the bit shifted out is the remainder.

A logical shift right moves every bit one place toward the LSB and puts a 0 into the MSB. The old LSB falls off the end.

Why it divides by 2: each bit moves to the position worth half as much, so the whole unsigned value halves. The bit that drops off is the remainder of dividing by 2.

  • 1110 (14) → 0111 (7), remainder 0.
  • 0111 (7) → 0011 (3), remainder 1: 7 ÷ 2 = 3 rounded down.

Shifting right k places divides by 2ᵏ and rounds down.

In hardware it is a shift-right register with its serial input tied to 0.

Logical shift right is only correct for unsigned numbers. On a two's complement negative number it shifts a 0 into the sign bit and turns the value positive. For signed values use the arithmetic shift right, which copies the sign bit instead.

Processors usually offer both instructions, often named SRL or LSR (logical) and SRA or ASR (arithmetic). Compilers use them to replace division by powers of 2, which is much cheaper than a divider.

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

Worked examples

Example

Shifting an 8-bit value

The register above holds 10010110 (150, unsigned). Apply one logical shift right.

  1. 1.

    Every bit moves one place right and a 0 enters on the left: 01001011.

  2. 2.

    The bit shifted out is 0, so 150 is even.

  3. 3.

    01001011 = 64 + 8 + 2 + 1 = 75 = 150 ÷ 2. ✓

Example

Two shifts with rounding

A 4-bit unsigned register holds 1110 (14). Shift it right logically twice.

  1. 1.

    First shift: 0111 = 7. Bit out: 0.

  2. 2.

    Second shift: 0011 = 3. Bit out: 1.

  3. 3.

    14 ÷ 4 = 3.5, rounded down to 3. ✓

Common mistakes

  • Using it on a negative two's complement number. 1010 (−6) becomes 0101 (+5), which is wrong; use an arithmetic shift.

  • Rounding to the nearest integer. The dropped bits are simply discarded, so the result always rounds down.

  • Shifting in a 1 from the left. A logical shift always fills with 0.

Practice Logical shift right

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

Learn it step by step

Logical shift right is taught in Registers and Adders and ALUs.