Cambridge IGCSE · Topic 1.1
IGCSE Computer Science 0478 / Topic 1 / IGCSE
Slide the bits .
Moving every bit one place to the left doubles a binary number; moving it one place to the right halves it. Processors use shifts as a very fast way to multiply and divide, but bits that fall off the end of the register are gone for good.
The key idea
A logical shift moves every bit in a register left or right by a number of places. Bits shifted off the end of the register are lost and zeros are shifted in at the opposite end. A left shift of n places multiplies a positive integer by 2n ; a right shift of n places divides it by 2n . If a 1 is lost, the answer is no longer correct: the most significant bits are lost in a left shift, the least significant bits in a right shift.
logical left shift by 2 places
0 0 0 1
0 1 1 0
0 1 0 1
1 0 0 0
lost ←
0s in ←
22 × 4
00010110 (22) becomes 01011000 (88)
Fig. 1: a left shift of 2 places multiplies 22 by 4; two 0s are lost on the left and two 0s enter on the right
Section 01
Shifting left .
In the lab, choose a number and press the left shift button. Each press moves every bit one place left and fills the right-hand end with 0.
Left shift Effect on a positive integer
1 place × 2
2 places × 4
3 places × 8
n places × 2n
Worked example Left shift 3 places
Perform a logical left shift of 3 places on 00001101. Give the result and its effect.
Move every bit 3 places left: the three leading 0s are lost.
Fill the 3 empty places on the right with 0: 01101000.
00001101 = 13 and 01101000 = 64 + 32 + 8 = 104 = 13 × 8.
Answer: 01101000: the number has been multiplied by 8
Show the first step Show all
Always give 8 bits after a shift. Writing 1101000 instead of 01101000 shows you have not kept the register size.
Section 02
Shifting right .
Now press the right shift button. The bits move towards the 1s column, 0s enter on the left, and the rightmost bits fall off.
Worked example Right shift 3 places
Perform a logical right shift of 3 places on 10110000.
Move every bit 3 places right: the three 0s on the right are lost.
Fill the 3 empty places on the left with 0: 00010110.
10110000 = 176 and 00010110 = 22 = 176 ÷ 8.
Answer: 00010110: the number has been divided by 8
Show the first step Show all
Worked example A 1 is lost
Perform a logical right shift of 1 place on 00010111 (23).
The rightmost 1 is shifted out and lost.
Result 00001011 = 11.
23 ÷ 2 = 11.5, but the half is lost, so the result is only the whole-number part.
Answer: 00001011 (11)
Show the first step Show all
Your turn
Perform a logical right shift of 2 places on 01100100. Give the result in binary and denary.
Show the answer
00011001 = 25 (100 ÷ 4)
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check +10 XP
What is the effect of a logical left shift of 1 place on a positive integer (if no 1s are lost)?
It multiplies the number by 2
It divides the number by 2
It adds 1 to the number
It multiplies the number by 10
Quick check +10 XP
What is the effect of a logical right shift of 2 places?
It divides the number by 4
It divides the number by 2
It multiplies the number by 4
It subtracts 2 from the number
Quick check +10 XP
In a logical shift, what fills the empty places at the end of the register?
Zeros
Ones
The bits that were lost
A copy of the leftmost bit
Quick check +10 XP
In the lab, what happens to a bit shifted past the end of the register?
It is lost
It wraps round to the other end
It moves into a ninth bit
It becomes a 0 in the same place
Section 03
When shifts go wrong .
Shifting only multiplies or divides correctly while no 1s fall off the end. Try shifting 11000101 left in the lab and watch the value.
Left shift loses the most significant bits: 11000101 (197) shifted left 2 places is 00010100 (20), not 788. The two 1s on the left were lost.
Right shift loses the least significant bits: any 1s shifted out on the right are the remainder of the division, so the answer is rounded down.
Multiple shifts: a shift of 3 places is the same as three shifts of 1 place.
"Shift left 2" means multiply by 4, not by 2. The factor is 2 to the power of the number of places.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
Finish the four checks above to unlock the exam questions
Exam style +20 XP
What is 00110100 after a logical right shift of 2 places?
00001101
11010000
00011010
00001110
Exam style +20 XP
What is 00000111 after a logical left shift of 4 places?
01110000
00111000
11100000
00011100
Exam style +20 XP
01100001 is shifted left 3 places. Why is the result not 97 × 8?
Bits with value 1 are shifted out of the register and lost
Zeros entering on the right reduce the value
A left shift divides instead of multiplying
The result is stored as a negative number
Exam style +20 XP
Which shift divides a positive 8-bit integer by 8?
A logical right shift of 3 places
A logical left shift of 3 places
A logical right shift of 8 places
A logical right shift of 4 places
Skill unlocked
Logical shifts, mastered.
This skill is now recorded on your profile. Keep the chain going.
- Rank
- Level
- Score
- Topics
Previous
Binary addition and overflow
Next
Two's complement for negative numbers