A-Level Computer Science / Unit 4: CPU Operation and Low-Level Processing

4.3.1 Binary Shifts and Their Effects

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

4.3.1 Binary Shifts and Their Effects

A binary shift moves every bit in a fixed-width bit pattern. The result depends on the direction of movement and on what happens at the two ends of the register. This section compares logical, arithmetic and cyclic shifts in both directions.

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

  • Perform left and right shifts on fixed-width binary values.
  • Distinguish logical, arithmetic and cyclic shifts.
  • Identify the bit that leaves the register and the bit introduced at the other end.
  • Explain why an arithmetic right shift preserves the sign of a two's-complement value.
  • Explain how cyclic shifts retain all original bits.
  • Use LSL #n and LSR #n with the accumulator.
  • Relate shifts to multiplication or division by powers of two when the interpretation permits it.
  • Recognise overflow, truncation and information loss caused by shifts.

Where This Page Fits

Page Main focus
4.3.1 Binary Shifts and Their Effects Logical, arithmetic and cyclic movement of bits.
4.3.2 Bitwise Logic and Masks AND, OR, XOR, testing bits and changing selected bits.
4.3.3 Using Bits to Read and Control Devices Applying flags and masks to sensor inputs and actuator outputs.
Structural note: The uploaded old webpage is about monitoring systems, not binary shifts. Its monitoring widget and sensor explanations are therefore reserved for 4.3.3, where they support device input and control. They have not been inserted into this shift page because that would mix two different syllabus objectives.

How to Read a Shift Diagram

Every example on this page uses an 8-bit register. Bit 7 is the most significant bit and bit 0 is the least significant bit.

Bit 7MSB
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0LSB

For each shift, ask three questions:

  1. Which direction do the existing bits move?
  2. Which bit leaves the fixed-width register?
  3. What enters the newly vacant position?
Fixed-width register: a register with a set number of bit positions. A bit moved beyond either end is no longer part of the stored value unless the processor records or wraps it.

Logical Shifts: Vacated Positions Receive Zero

Logical shift: every stored bit moves left or right, the bit leaving the register is discarded, and a zero enters at the opposite end.

Logical left shift

Before 00110110 Unsigned 54
After 01101100 Unsigned 108

Every bit moves one place left. The original bit 7 leaves the register and zero enters bit 0. Here no significant 1 is lost, so the unsigned value doubles.

Logical right shift

Before 10110101 Unsigned 181
After 01011010 Unsigned 90

Every bit moves one place right. The original bit 0 is lost and zero enters bit 7. For an unsigned integer, this produces integer division by two. The lost 1 represents the discarded remainder.

Common mistake: A logical right shift always inserts zero at the left. It does not copy the original sign bit.

Logical Shift Instructions: LSL and LSR

In the syllabus teaching instruction set, logical shifts operate on the accumulator:

Instruction Effect on ACC Bit introduced
LSL #n Shift the bits in ACC left by n places. Zero enters from the right.
LSR #n Shift the bits in ACC right by n places. Zero enters from the left.
ACC = 00010111 LSL #2 ACC = 01011100

The instruction above is equivalent to two one-place logical left shifts:

00010111
00101110
01011100
Exam tip: When shifting by more than one place, show each intermediate pattern. It makes lost bits and inserted zeros easier to check.

Arithmetic Shifts: Preserve Signed Meaning Where Possible

Arithmetic shifts are intended for signed two's-complement values. The most important difference appears during a right shift.

Arithmetic right shift: shift all bits right while copying the original sign bit into the vacant most significant position.

Arithmetic right shift of a positive value

Before 00110110 +54
After 00011011 +27

Arithmetic right shift of a negative value

Before 11010100 −44 in 8-bit two's complement
After 11101010 −22

The leftmost 1 is copied because it is the sign bit. Inserting zero instead would turn the result into a positive number and destroy the signed interpretation.

Arithmetic left shift

An arithmetic left shift usually moves the bit pattern in the same way as a logical left shift: bits move left and zero enters from the right. The pattern is interpreted as signed, so the result is only valid when the required signed value still fits.

Before 11101010 −22
After 11010100 −44
Overflow warning: Shifting 01011100 left gives 10111000. The original value is +92, but +184 cannot be represented in 8-bit two's complement. The new pattern would be interpreted as a negative number, so signed overflow has occurred.

Cyclic Shifts: The Leaving Bit Returns at the Other End

Cyclic shift (rotation): bits move left or right, and the bit leaving one end re-enters at the other end. No original bit is discarded.

Cyclic left

Before 10110001
After 01100011

The original leftmost 1 wraps around into bit 0.

Cyclic right

Before 10110001
After 11011000

The original rightmost 1 wraps around into bit 7.

Common mistake: A cyclic shift does not insert zero. The outgoing bit is reused at the opposite end.

Shifting More Than One Place

A shift by n places is equivalent to repeating a one-place shift n times. The rule is applied again at every stage.

Step Logical right shift Arithmetic right shift Cyclic right shift
Start 11001011 11001011 11001011
After 1 place 01100101 11100101 11100101
After 2 places 00110010 11110010 11110010

The arithmetic and cyclic results happen to match in this particular two-step example, but the processes are different: arithmetic right copies the current sign bit, while cyclic right wraps the outgoing bit.

How Shifts Affect Numerical Values

Shift Typical numerical effect Condition
Logical left by n Unsigned value × 2n Only if no significant 1 is shifted out.
Logical right by n Unsigned integer value ÷ 2n Any discarded bits form a lost remainder.
Arithmetic right by n Signed value divided by 2n The sign is preserved; negative odd values require attention to rounding.
Arithmetic left by n Signed value × 2n Only if the signed result remains representable.
Cyclic left or right No general multiply/divide rule Rotation preserves the bit count, not the numerical magnitude.
Exam tip: Do not claim that every left shift doubles and every right shift halves. First state the shift type, number representation and whether significant bits are lost.

What Happens to a Bit That Leaves?

Shift type Outgoing bit Incoming bit
Logical Discarded from the stored value. 0
Arithmetic right Discarded from the stored value. Copy of the sign bit
Arithmetic left Discarded; may reveal signed overflow. 0
Cyclic Wrapped to the opposite end. The same outgoing bit

Some processor designs also copy the outgoing bit into a carry flag. Only use that behaviour when it is stated or when the processor model defines it.

Interactive: Binary Shift Visualiser

Enter an 8-bit pattern, choose the shift type and direction, and select how many places to move. Step through the shift one place at a time to see the outgoing and incoming bits.

Before this step
Unsigned 54 · Signed 54
Logical left
Outgoing 0
Incoming 0
After this step
Unsigned 108 · Signed 108

Step 1 of 1

Move every bit one place left

The most significant bit leaves the register and zero enters at bit 0.

Final result 01101100

Common Mistakes and Misconceptions

  • Moving bits in the wrong direction because the instruction says “left” but the written arrow was misread.
  • Changing only one bit instead of moving the complete bit pattern.
  • Inserting 1 during a logical shift. Logical shifts insert zero.
  • Using a logical right shift on a negative two's-complement value and claiming the sign is preserved.
  • Forgetting to wrap the outgoing bit during a cyclic shift.
  • Assuming an arithmetic left shift cannot overflow.
  • Applying the multiply/divide rule without checking for lost significant bits.
  • Treating a shift by three places as one unexplained jump rather than three repeated one-place operations.

Exam Tips

Label the shift before calculating

Write the type, direction and number of places, for example: arithmetic right by two.

Show the end rule

State what enters the vacant position: zero, the sign bit, or the outgoing wrapped bit.

Keep the width fixed

An 8-bit result must still contain exactly eight bits. Do not add a ninth bit to keep a value that should have left the register.

Practice

Perform the shifts

  1. Logically shift 01011001 left by one place.
  2. Logically shift 11100110 right by two places.
  3. Arithmetically shift 10110100 right by one place.
  4. Cyclically shift 01101001 left by three places.
  5. Cyclically shift 10010110 right by two places.

Explain the effect

  1. Why does arithmetic right preserve the leftmost bit?
  2. Why is LSR #1 unsuitable for halving a negative two's-complement value?
  3. Under what condition does LSL #2 multiply an unsigned value by four correctly?
  4. Explain why a cyclic shift cannot generally be described as multiplication or division.
  5. How can an arithmetic left shift produce a negative-looking result from a positive input?

Assembly-language application

ACC contains 00011101. Show ACC after each independent instruction: LSL #1, LSL #3, LSR #1 and LSR #2.

Review

Shift What enters? What happens to the outgoing bit?
Logical left/right 0 Discarded
Arithmetic right Copy of sign bit Discarded
Arithmetic left 0 Discarded; overflow may occur
Cyclic left/right Outgoing bit from the other end Wrapped around
Final check: Can you perform all six combinations—logical, arithmetic and cyclic, each moving left and right—and explain the numerical effect?