ScholaFly

CS01-08 Computer Science Watch

Binary shifts

Watch on YouTube

In this lesson

In this video you'll learn about binary shifts for GCSE Computer Science.

By the end: Apply a logical binary shift left or right to an 8-bit number, and state the arithmetic effect of the shift as a multiplication or division by a power of 2.

What it covers

  1. 0:51 A binary shift moves every bit in a pattern, every one and every zero, the same number of places, either left or right
  2. 3:17 A first one to work: shift zero zero zero one zero one one zero two places to the left
  3. 7:32 This time there is no pattern at all, only a job: a program must multiply a number by eight using a shift

Key words

About this video

Binary Shifts (Logical and Arithmetic Shifts) | GCSE Computer Science

How a binary shift left or right multiplies or divides by a power of 2, with logical and arithmetic shifts and worked 8-bit examples.
AQA 8525, Edexcel 1CP2 and OCR J277 GCSE. Binary and number bases 8 of 9.
Full Binary and number bases playlist: https://www.youtube.com/playlist?list=PLXHIB7m15mQ8
More at https://scholafly.com

Watch first: Denary (Decimal) to Binary and Back - https://youtu.be/8BNbDYvaatg
Video code: CS01-08 (search "ScholaFly CS01-08")

Videos in this chapter:
CS01-00 Binary and number bases - Intro: https://youtu.be/FhBTIBfALl0
CS01-01 Why computers use binary: https://youtu.be/u_E79oQc3vg
CS01-02 Denary to binary and back: https://youtu.be/8BNbDYvaatg
CS01-03 Why hexadecimal exists: https://youtu.be/3xFsSpMReow
CS01-04 Denary and hexadecimal: https://youtu.be/UYWEpHOGYz0
CS01-05 Binary and hexadecimal: https://youtu.be/QNt2RchgCJg
CS01-06 Binary addition: https://youtu.be/tMuW9_Vn7Ig
CS01-07 Overflow: https://youtu.be/hDSxVYkfpzk
CS01-08 Binary shifts: https://youtu.be/5SU-12ritd8
CS01-09 Negative numbers and two's complement

#GCSEComputerScience #BinaryAndNumberBases #BinaryShifts

For teachers
This GCSE Computer Science lesson teaches binary shifts. By the end, students should be able to apply a logical binary shift left or right to an 8-bit number, and state the arithmetic effect of the shift as a multiplication or division by a power of 2. It works through three worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.

Exam board specification references:
AQA GCSE Computer Science (8525)
- 3.3.4 Binary arithmetic
Pearson Edexcel Level 1/Level 2 GCSE (9-1) in Computer Science
- 2.1.4 Binary
Cambridge OCR Level 1/Level 2 GCSE (9-1) in Computer Science
- 1.2.4 Data storage - Numbers

Read the transcript

Ask a computer to multiply a number by eight, and often it does not multiply at all. It slides every bit of the number three places to the left. Anything that falls off the end is thrown away. That leaves a puzzle. A slide of three places somehow means times eight, and a bit that falls off takes part of the number with it. Both halves come from one row of column values.

This is video eight of nine in Binary and number bases. If reading a pattern against its column values feels shaky, Denary to binary and back covers that first.

A binary shift moves every bit in a pattern, every one and every zero, the same number of places, either left or right. The pattern sits in a fixed row of eight slots. In a logical shift, any slot left empty is filled with a zero, and any bit pushed out of the end is gone for good. Now bring back the header, the row of column values over those slots: one hundred and twenty-eight, sixty-four, thirty-two, sixteen, eight, four, two, one. Slide a bit one place to the left. Is it now worth more, or less? More, twice as much. Each place is worth double the one on its right, so every bit doubles and the whole number doubles. Left can feel like moving down, but the bigger values are on the left. Denary, our everyday base ten, works the same way with tens: slide the digits of forty-two one place left, fill the gap with a zero, and you get four hundred and twenty. Now, one place right halves the number. What do three places right do to it? Three places right divide it by eight. Half, then half again, then half again, leaves one eighth. That gives the rule for every logical shift. Left by n places multiplies by two to the power n. Right by n places divides by two to the power n. So every shift has two answers: the new pattern, and what the shift did to the value. Exam questions call that second answer the arithmetic effect.

Here is a first one to work: shift zero zero zero one zero one one zero two places to the left. Start by reading its value. The ones sit under sixteen, four and two, and sixteen add four add two is twenty-two. Next, slide every bit two places left. The two zeros at the far left drop out, which costs nothing, because they were zeros. Two slots open at the right-hand end, and a logical shift fills both with zeros. The new pattern is zero one zero one one zero zero zero. Read it against the header. What is the new pattern worth? The new pattern is worth eighty-eight. Its ones sit under sixty-four, sixteen and eight, and those add up to eighty-eight. Twenty-two became eighty-eight, and eighty-eight divided by twenty-two is four. That matches the rule: two places left is two to the power two, which is four. The two answers, then, are the pattern zero one zero one one zero zero zero, and the effect, multiply by four.

Now a shift to the right, where bits do fall off: one zero one one zero one zero zero, three places right. Its ones sit under one hundred and twenty-eight, thirty-two, sixteen and four. Add those and the pattern is worth one hundred and eighty. Slide every bit three places right. The last three bits, one zero zero, drop out of the right-hand end. Three zeros fill the gap at the left. The new pattern is zero zero zero one zero one one zero, which reads as twenty-two. Three places right should divide by eight. But one hundred and eighty divided by eight is twenty-two point five, not twenty-two. Where did the point five go, and why is twenty-two still correct? The point five left with the lost bits. Those bits held a four, and four is the remainder, which the slots have no room to keep. That is how a right shift is meant to behave. It divides and throws the remainder away, so twenty-two is not a slip in your working. A calculator would keep the half, but whole-number columns have no place for one. Two answers again: the pattern zero zero zero one zero one one zero, and the effect, divide by eight with the remainder lost. Bits can fall off the left end too. Shift one zero zero zero zero zero one one one place left, and the leading one drops out. Before the shift, the ones sit under one hundred and twenty-eight, two and one, which makes one hundred and thirty-one. After it, the ones sit under four and two, which makes six, not double. A result too big for eight slots is what the Overflow video is about.

This time there is no pattern at all, only a job: a program must multiply a number by eight using a shift. Three places right, two places left, or three places left: which multiplies by eight? Three places left, because each place left doubles, and two times two times two is eight. Three places right would divide by eight, and two places left only multiplies by four. One examiner's report says: Students did not perform so well in stating the arithmetic effect of applying a binary shift even though guidance was given in the stem of the question. In plain words, the weak part was the second answer, what the shift did to the value. And the question itself had pointed the way. The fix is a habit. Every time you shift, write the new pattern, then write the effect in words, such as multiply by four or divide by eight.

One exam board asks for a second kind of shift as well. Find your board in the list: if it says logical shift only, this part is not on your paper. The second kind is the arithmetic shift. On a move to the right, it fills the empty slots at the left with copies of the leftmost bit, instead of zeros. Take one zero one one zero one zero zero, one place right. A logical shift gives zero one zero one one zero one zero. What pattern does the arithmetic shift give for that same move? One one zero one one zero one zero. The leftmost bit was a one, so a one is copied into the gap instead of a zero. The reason is signed numbers, which can be negative, and where the leftmost bit marks a negative. Copying that bit keeps a negative number negative. The two's complement video teaches how those numbers are read. Two answers here too. Read as a signed number, the leftmost column is worth minus one hundred and twenty-eight. Before the shift, the ones give minus one hundred and twenty-eight, add thirty-two, add sixteen, add four. That makes minus seventy-six. After the shift, the ones give minus one hundred and twenty-eight, add sixty-four, add sixteen, add eight, add two. That makes minus thirty-eight, so minus seventy-six has halved, and the effect is divide by two. Watch two similar names. The arithmetic effect is what any shift does to a value. An arithmetic shift is this second kind of shift, the one that copies the leftmost bit.

Four questions to finish, and each one wants the pattern and the effect where it can. Which way does a shift go to make a number bigger, and why? Left. Each bit moves into a place worth double, so the value doubles for every place. Now try a left shift. Shift five three places left: what pattern, and what effect? Zero zero one zero one zero zero zero, and the effect is multiply by eight. Five has become forty. Now a right shift. Two hundred and one, two places right: what pattern, and what effect? Zero zero one one zero zero one zero, which is fifty. The effect is divide by four, and a remainder of one fell off the end. One more. A shift turned twelve into three. Which shift was it? Two places to the right. Three is twelve divided by four, and four is two to the power two. And that is the slide from the start. Three places left puts every bit in a place worth eight times as much, so the number is multiplied by eight, as long as nothing falls off the end.

If shifts feel like this one's yours, mark it with your thumb, and when you revise you can skip it. If they still feel slippery, save it for later: three or four shifts in, they start to feel normal.

Next in the chapter: Negative numbers and two's complement, where the leftmost bit starts to mean minus.

For more, visit scholafly.com, or watch the next video.

Related terms

For: AQA GCSE 8525, Edexcel GCSE 1CP2, OCR GCSE J277

On the specification

BoardSpecStatement
AQA GCSE 85253.3.4Binary arithmetic
Edexcel GCSE 1CP22.1.4Binary
OCR GCSE J2771.2.4Data storage - Numbers
For teachers

This GCSE Computer Science lesson teaches binary shifts. By the end, students should be able to apply a logical binary shift left or right to an 8-bit number, and state the arithmetic effect of the shift as a multiplication or division by a power of 2. It works through three worked examples and the mistakes examiners report, and suits Foundation and Higher tier students.