Secondary Computer Science / 1.3 Working with Fixed-Width Binary

1.3.2 Logical Shifts and Bit Loss

🔒 Lesson slides are available to signed-in users. Sign in

1.3.2 Logical Shifts and Bit Loss

A display controller stores a brightness value in an 8-bit register. To change the value quickly, the processor can move every bit left or right. This operation is called a logical binary shift.

Shifting a positive binary integer can have a similar effect to multiplying or dividing by a power of two. However, an 8-bit register has fixed boundaries. Bits that move beyond those boundaries are lost.

By the end of this section, you should be able to:

  • describe what happens during a logical binary shift;
  • perform logical left shifts on positive 8-bit binary integers;
  • perform logical right shifts on positive 8-bit binary integers;
  • perform more than one shift on the same binary value;
  • identify which bits are lost and where zeros are inserted;
  • explain the multiplication or division effect of a shift;
  • explain why bit loss can make the numerical result different from the expected calculation.

Working inside an 8-bit register

A register with a fixed width has a limited number of bit positions. In this lesson, every register has exactly eight positions.

Register 寄存器: a small storage location inside the processor that holds a bit pattern.

Fixed width 固定位宽: using a set number of bit positions, such as eight bits.

Most significant bit 最高有效位: the leftmost bit, which has the greatest place value.

Least significant bit 最低有效位: the rightmost bit, which has the smallest place value.
Bit position 7 6 5 4 3 2 1 0
Place value 128 64 32 16 8 4 2 1
Example value 0 0 1 0 1 1 0 1

The example pattern 00101101 represents:

32 + 8 + 4 + 1 = 45

Common mistake

A logical shift does not increase the size of the register. An 8-bit pattern remains eight bits after the shift.

What is a logical shift?

A logical shift moves every bit in the register by the same number of positions. The movement can be towards the left or towards the right.

Logical binary shift 逻辑二进制移位: moving every bit in a binary pattern left or right, discarding bits that leave the register and filling newly empty positions with zeros.

Shift count 移位次数: the number of positions through which each bit is moved.
1 Choose a direction

Move every bit left or move every bit right.

2 Move every bit

Each bit travels the same number of positions.

3 Remove escaping bits

Bits that pass beyond the register boundary are lost.

4 Insert zeros

Zeros fill the newly empty positions at the opposite end.

Common mistake

A logical shift does not wrap a lost bit around to the other side. That would be a different type of operation. In a logical shift, the lost bit disappears and a zero enters at the opposite end.

Logical left shifts

In a logical left shift, every bit moves towards the most significant end of the register. A zero enters at the right.

Logical left shift 逻辑左移: moving every bit towards the left, losing any bit that passes beyond the left boundary and inserting zero on the right.
Before 0 0 1 0 1 1 0 1
After 0 1 0 1 1 0 1 0

The original pattern 00101101 represents 45. After one logical left shift, the result is 01011010, which represents 90.

45 × 2 = 90

No significant 1-bit was lost from the left, so the shift successfully doubled the value.

Answer-building tip

Describe both ends of the register: all bits move left, the leftmost bit is lost, and a zero enters at the right.

Why a left shift can multiply by two

Moving a bit one position to the left moves it into a column with twice the place value.

Bit before shifting Original place value New place value
1 in the 4-column 4 8
1 in the 16-column 16 32
1 in the 32-column 32 64

Therefore, one safe left shift multiplies a positive integer by 2. Two safe left shifts multiply by 22 = 4. Three safe left shifts multiply by 23 = 8.

Number of left shifts Expected multiplication
1 × 2
2 × 4
3 × 8

Important condition

The multiplication relationship is reliable only when no significant 1-bit is lost from the left side of the register.

Worked example: multiple left shifts

Perform two logical left shifts on 00010111.

Step 1: find the original value

00010111 = 23

Step 2: shift left once

00010111 → 00101110

The first result represents 46.

Step 3: shift left a second time

00101110 → 01011100

The final result represents 92.

Step 4: check the expected multiplication

23 × 22 = 23 × 4 = 92

No 1-bits were lost, so the result matches multiplication by four.

When a left shift loses an important bit

Consider the positive 8-bit value 10110101, which represents 181.

10110101 → logical left shift → 01101010

The most significant bit is 1. When all bits move left, this 1 leaves the register and is lost. A zero enters at the right.

Calculation Value
Original value 181
Expected multiplication 181 × 2 = 362
Stored 8-bit result 01101010 = 106

The correct value 362 cannot be represented in eight positive bits. Since the leading 1 is removed, the stored result is not equal to 181 × 2.

Bit loss 位丢失: the removal of a bit when it is shifted beyond the boundary of a fixed-width register.

Data integrity 数据完整性: the accuracy and consistency of stored data. Losing an important bit can change the value unexpectedly.

Common mistake

Do not automatically state that every left shift doubles the stored value. Check whether a 1-bit leaves the left end of the register.

Logical right shifts

In a logical right shift, every bit moves towards the least significant end of the register. A zero enters at the left.

Logical right shift 逻辑右移: moving every bit towards the right, losing any bit that passes beyond the right boundary and inserting zero on the left.
Before 1 0 1 1 0 1 1 0
After 0 1 0 1 1 0 1 1

The original pattern 10110110 represents 182. After one logical right shift, the result is 01011011, which represents 91.

182 ÷ 2 = 91

The rightmost bit was 0, so no numerical remainder was lost.

Answer-building tip

For a right shift, state that: all bits move right, the rightmost bit is lost, and a zero enters at the left.

Why a right shift can divide by two

Moving a bit one position to the right moves it into a column with half the place value.

Bit before shifting Original place value New place value
1 in the 64-column 64 32
1 in the 16-column 16 8
1 in the 2-column 2 1

Therefore, one right shift performs integer division by 2. Two right shifts divide by 22 = 4. Three right shifts divide by 23 = 8.

Number of right shifts Division effect
1 ÷ 2
2 ÷ 4
3 ÷ 8

Common mistake

Binary integer storage does not retain a fractional part. When an odd positive number is shifted right, the lost least significant 1 represents the discarded remainder.

Right shifting an odd value

Consider 01101101, which represents 109.

01101101 → logical right shift → 00110110

The least significant bit is 1. It leaves the register and is lost. The result 00110110 represents 54.

Interpretation Value
Exact denary calculation 109 ÷ 2 = 54.5
Stored integer result 54
Lost information Remainder 1

The computer stores the whole-number part only. The discarded rightmost bit accounts for the lost remainder.

Use accurate terminology

Say that the right shift performs integer division. Do not claim that it stores the decimal value 54.5.

Worked example: multiple right shifts

Perform two logical right shifts on 11100101.

Step 1: find the original value

11100101 = 229

Step 2: shift right once

11100101 → 01110010

The first shift produces 114. The original rightmost 1 has been lost.

Step 3: shift right a second time

01110010 → 00111001

The final result 00111001 represents 57.

Step 4: compare with integer division

229 ÷ 22 = 229 ÷ 4 = 57 remainder 1

Two right shifts divide by four using whole-number arithmetic. The information needed to represent the remainder has left the register.

Comparing left and right shifts

Feature Logical left shift Logical right shift
Direction of movement Towards the most significant end Towards the least significant end
Bit that may be lost Most significant bit Least significant bit
Position filled with zero Right side Left side
Numerical effect of one shift Multiply by 2 when no important bit is lost Integer divide by 2
Effect of n shifts Multiply by 2n, subject to bit loss Integer divide by 2n
Possible information loss A large place-value bit may disappear A remainder bit may disappear

Predicting a result before shifting

A denary check can help you decide what a shift should do and whether bit loss may affect the result.

Question Useful check
One left shift Calculate the original value × 2
Two left shifts Calculate the original value × 4
One right shift Calculate the original value using integer division by 2
Three right shifts Calculate the original value using integer division by 8
Possible left-shift loss Check whether the expected result is greater than 255
Possible right-shift remainder Check whether a 1 will leave the right end

Show the process

In a written answer, show the shifted 8-bit pattern and then state its denary effect. Do not provide only the multiplication or division rule.

Common mistakes and misconceptions

  • Moving only the 1-bits. Every bit position moves, including positions containing 0.
  • Filling empty positions with 1. A logical shift always introduces 0.
  • Wrapping the lost bit around to the other end. Logical shifts do not rotate.
  • Changing the register width. The result must remain an 8-bit pattern.
  • Claiming that every left shift doubles the stored value without checking whether a 1-bit was lost.
  • Claiming that right shifting an odd number stores a decimal fraction.
  • Confusing the direction of zero-fill: left shifts insert zero on the right; right shifts insert zero on the left.
  • Applying signed-number rules in this lesson. The values here are interpreted as positive 8-bit integers.

Interactive: Logical Shift Register Laboratory

Enter a positive 8-bit binary integer, select a direction and choose how many positions to shift. The laboratory will animate the bits, identify lost bits and explain the numerical effect.

Interactive investigation

Move bits inside an 8-bit register

Shifted result 01011010 45 × 2 = 90
Denary value: 45
1. Choose the shift operation

Direction

Number of positions

Every bit will move one place left. The leftmost bit will be lost, and zero will enter on the right.

Apply or animate the shift to investigate the result.

2. Follow the bits

stored bit lost bit inserted zero
Lost from register 0
Zeros inserted 0
Original value 45
Expected operation × 2
Expected denary value 90
Stored denary result 90
Bit-loss check The bit lost from the left was 0, so the stored value is correctly doubled.

Shift challenge

Predict the result

Perform two logical right shifts on 11010100.

Move all bits and remember to insert zeros.

Describe three things

When explaining a logical shift, include: the direction of movement, the bit or bits lost, and where zeros are inserted.

Practice

Core questions

  1. Define the term logical binary shift.
  2. Describe what happens to the bits during one logical left shift.
  3. Describe what happens to the bits during one logical right shift.
  4. Perform one logical left shift on 00110110.
  5. Perform two logical left shifts on 00011001.
  6. Perform one logical right shift on 10101100.
  7. Perform three logical right shifts on 11100000.
  8. State the numerical effect of two safe logical left shifts on a positive binary integer.
  9. State the numerical effect of three logical right shifts on a positive binary integer.
  10. Explain why a zero is inserted after a bit pattern has been shifted.
  11. Explain why left shifting 11000110 once does not produce the stored value 396.
  12. Explain what happens to the remainder when an odd positive integer is shifted right once.
  13. State which bit is lost during:
    1. a logical left shift;
    2. a logical right shift.
  14. Explain why a logical shift must keep the result at eight bits in this lesson.

Extension questions

  1. Convert 00100111 to denary, perform two logical left shifts, and check the result using multiplication.
  2. Perform two logical right shifts on 10111011. Identify every bit that is lost.
  3. A student claims that shifting 11100001 left once gives twice its original value. Explain why the claim is incorrect.
  4. Find an 8-bit positive binary value that can be shifted left three times without losing a 1-bit.
  5. Explain why several different original values can produce the same result after enough right shifts.
  6. A system uses logical left shifts as a quick multiplication method. Describe a check that should be performed before the result is accepted.
Check selected answers
  1. 00110110 shifted left once becomes 01101100.
  2. 00011001 shifted left twice becomes 01100100.
  3. 10101100 shifted right once becomes 01010110.
  4. 11100000 shifted right three times becomes 00011100.
  5. Two safe left shifts multiply the value by 22 = 4.
  6. Three right shifts perform integer division by 23 = 8.
  7. 00100111 is 39. Two left shifts produce 10011100, which is 156. This agrees with 39 × 4.
  8. 10111011 shifted right twice becomes 00101110. The bits lost from the right are 1 and then 1.

Review

Key ideas

  • A logical shift moves every bit left or right.
  • The register remains a fixed width.
  • Bits that move beyond the register boundary are lost.
  • Zeros fill the empty positions at the opposite end.
  • A logical left shift inserts zero on the right.
  • A logical right shift inserts zero on the left.
  • One safe left shift multiplies a positive value by two.
  • One right shift performs integer division by two.
  • Multiple shifts use powers of two.
  • Losing a most significant 1-bit can make a left-shift result incorrect as multiplication.
  • Losing a least significant 1-bit during a right shift discards a remainder.

Quick self-check

  1. Can I perform a logical left shift?
  2. Can I perform a logical right shift?
  3. Can I perform several shifts?
  4. Can I identify the bits that leave the register?
  5. Can I explain where zeros are inserted?
  6. Can I explain the multiplication and division effects?
  7. Can I explain when bit loss changes the expected result?

One-minute exit task

Perform two logical left shifts on 01010110. State the final 8-bit pattern and explain whether the result is equal to the original value multiplied by four.