J277 5: Binary Addition, Shifts and Hexadecimal

OCR GCSE COMPUTER SCIENCE · J277 · PAPER 1

Addition, shifts and hex

Adding binary numbers, spotting overflow, multiplying with a shift, and reading hexadecimal.

Paper 1 · Lesson 5

1 / 24
volgende
Slide 1: Slide
newEditorComputer ScienceUpper Secondary (Key Stage 4)GCSE

In deze les zitten 24 slides, met interactieve quizzen en tekstslides.

time-iconLesduur is: 60 min
Dit is niet oké

Introductie

OCR GCSE Computer Science (J277), Paper 1, lesson 5 of 26. Students add two 8-bit binary numbers using carries, recognise overflow errors, use binary shifts to multiply and divide (and explain the loss of precision), and learn why hexadecimal is used and how to convert between binary, hexadecimal and denary (00 to FF, 0 to 255). Includes a retrieval do-now on lesson 4, worked examples in terminal-style boxes, picture questions, drag-and-drop, an open question, fill in the blanks and an exam-style question with mark scheme. This lesson was created with AI assistance.

Onderdelen in deze les

OCR GCSE COMPUTER SCIENCE · J277 · PAPER 1

Addition, shifts and hex

Adding binary numbers, spotting overflow, multiplying with a shift, and reading hexadecimal.

Paper 1 · Lesson 5

Welcome the class. This lesson covers J277 section 1.2 (data storage, numbers): binary addition, overflow, binary shifts and hexadecimal.

Say: last lesson was about reading binary. Today is about doing arithmetic with it, and about the shorthand programmers use to write it.

Device-free: show the cover on the board and ask students to write the title and date.

Cover photo: Ferenc Almasi / Unsplash, shown as a hologram.

01 · LEARN · MISSION BRIEFING

By the end of this lesson

01

Add two 8-bit binary numbers and recognise an overflow error.

02

Apply left and right binary shifts and explain the effect.

03

Explain why hexadecimal is used and convert between binary, hex and denary.

SYSTEM VOICE

System online. Mission briefing. Today you will add binary numbers and spot when they overflow, shift bits left and right to multiply and divide, and decode hexadecimal, the shorthand that programmers use for binary.

Play the system voice clip (the play button). Its words are on the slide: "System online. Mission briefing. Today you will add binary numbers and spot when they overflow, shift bits left and right to multiply and divide, and decode hexadecimal, the shorthand that programmers use for binary."

Read the three outcomes aloud. Return to them at the exit poll.

Device-free: read the briefing aloud and have students copy the three outcomes.

02 · CHECK · DO NOW (LESSON 4)

Four quick questions

Q1  What is the largest denary number that 8 bits can hold?

Q2  Convert 01010101 into denary.

Q3  Convert denary 40 into 8-bit binary.

Q4  How many megabytes are there in 2.5 GB?

255

64 + 16 + 4 + 1 = 85

32 + 8 = 00101000

2.5 × 1000 = 2500 MB

Retrieval from lesson 4. Give 4 minutes, then click to reveal each answer.

Q1: 255 (11111111). Q2: 01010101 = 64 + 16 + 4 + 1 = 85. Q3: 40 = 32 + 8 = 00101000. Q4: 2.5 GB × 1000 = 2500 MB.

Misconception: Q1 is 255, not 256; 256 is the number of different values (0 to 255).

Device-free: students answer on mini whiteboards or in the back of their books.

Recap of lesson 4: how many different values can 8 bits represent?

A

8

B

255

C

256

D

128

Answer: 256 (2 to the power 8). The values run from 0 to 255, so 255 is the largest number, not the number of values.

That is the misconception to watch for: 255 is the most common wrong answer.

Device-free: students hold up A, B, C or D cards. Image credit: Markus Spiske / Unsplash

01 · LEARN · BINARY ADDITION

Four rules for adding bits

0 + 0 = 0

0 + 1 = 1

1 + 1 = 10  write 0, carry 1

1 + 1 + 1 = 11  write 1, carry 1

Work from right to left, just like column addition in denary. A carry moves into the next column to the left.

Big idea: binary addition follows the same column method as denary, but you carry as soon as a column reaches 2.

1 + 1 = 2 in denary, which is 10 in binary: write 0 and carry 1. 1 + 1 + 1 (two bits plus a carry) = 3 in denary, which is 11 in binary: write 1 and carry 1.

Misconception: writing 2 in a binary column. Binary only has the digits 0 and 1.

Device-free: students copy the four rules; they will need them for every addition today. Image credit: Brecht Corbeel / Unsplash

01 · LEARN · WORKED EXAMPLE

Adding two bytes, column by column

▮ TERMINAL // binary_add.txt

1        0 1 1 0 1 0 1 1   (107)

2      + 0 0 1 1 0 1 1 0    (54)

3  carry 1 1 1 1 1 1 0 0

4        ---------------

5        1 0 1 0 0 0 0 1   (161)

6  CHECK 107 + 54 = 161

How it works

Start at the right-hand column.

The carry row shows the 1 carried into each column from the one on its right.

Check by converting both numbers and the answer to denary.

Click to reveal a line at a time. Model the columns aloud from the right.

Column 1 (1s): 1 + 0 = 1. Column 2: 1 + 1 = 10, write 0 carry 1. Column 3: 0 + 1 + carry 1 = 10, write 0 carry 1. Column 4: 1 + 0 + 1 = 10, write 0 carry 1. Column 5: 0 + 1 + 1 = 10, write 0 carry 1. Column 6: 1 + 1 + 1 = 11, write 1 carry 1. Column 7: 1 + 0 + 1 = 10, write 0 carry 1. Column 8: 0 + 0 + 1 = 1.

Answer 10100001. Check: 107 + 54 = 161, and 128 + 32 + 1 = 161.

Device-free: students copy the sum into their books and write the carries in a different colour.

What is 00110101 + 01001110 in 8-bit binary?

A

10000011

B

01111011

C

10000111

D

10000001

Answer: 10000011. Working from the right: 1 + 0 = 1; 0 + 1 = 1; 1 + 1 = 0 carry 1; 0 + 1 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; 0 + 1 + 1 = 0 carry 1; 0 + 0 + 1 = 1.

Check in denary: 00110101 = 53, 01001110 = 78, 53 + 78 = 131, and 10000011 = 128 + 2 + 1 = 131.

Distractors: 01111011 (123) is what you get by ignoring every carry. 10000111 (135) and 10000001 (129) are single-column slips.

Device-free: students do the sum on mini whiteboards, then hold up. Image credit: Adi Goldstein / Unsplash

01 · LEARN · OVERFLOW

When the answer is too big for 8 bits

The largest number 8 bits can hold is 255. If an addition needs a 9th bit, that bit has nowhere to go. This is an overflow error.

11000000 + 10000000
192 + 128 = 320

The full answer 1 01000000 needs 9 bits. Only 01000000 (64) is stored, so the result is wrong.

Key term: overflow error = the result of a calculation is too large to fit in the number of bits available.

Check the example: 11000000 = 128 + 64 = 192. 10000000 = 128. 192 + 128 = 320. 320 = 256 + 64 = 101000000 in 9 bits. The 9th bit (256) is lost, so 01000000 = 64 is stored.

Why it matters: a program can carry on with a wrong value without any warning; the CPU may set a flag to show an overflow has happened.

Device-free: ask students to find two 8-bit numbers whose total is exactly 256 and explain why that overflows. Image credit: Logan Voss / Unsplash

Will each addition cause an overflow error in 8 bits?

OVERFLOW

NO OVERFLOW



11110000 + 00010000

01111111 + 00000001

01010101 + 00101010

10000000 + 10000000

Students convert each pair to denary and check whether the total is more than 255.

Answers. Overflow: 11110000 + 00010000 = 240 + 16 = 256. 10000000 + 10000000 = 128 + 128 = 256. No overflow: 01111111 + 00000001 = 127 + 1 = 128. 01010101 + 00101010 = 85 + 42 = 127.

Shortcut: if both numbers start with a 1, the total is at least 256, so it always overflows.

Device-free: write the four sums on the board; students write O (overflow) or N (no overflow) for each.

01 · LEARN · BINARY SHIFTS

Shifting bits multiplies and divides

▮ TERMINAL // binary_shift.txt

1  START   00010110  = 22

2  LEFT 2  01011000  = 88  (x 4)

3  RIGHT 1 00001011  = 11  (/ 2)

Left shift: bits move left, 0s fill in on the right.

Right shift: bits move right, 0s fill in on the left.

SYSTEM VOICE

Binary shift. Moving every bit one place to the left multiplies the number by 2. Moving every bit one place to the right divides it by 2. Bits that fall off the end are lost.

Play the system voice clip. Its words are on the slide: "Binary shift. Moving every bit one place to the left multiplies the number by 2. Moving every bit one place to the right divides it by 2. Bits that fall off the end are lost."

Click to reveal each line. 00010110 = 22. Left shift 2 places: 01011000 = 64 + 16 + 8 = 88, which is 22 × 4. Right shift 1 place: 00001011 = 8 + 2 + 1 = 11, which is 22 ÷ 2.

Rule: a left shift of n places multiplies by 2 for each place (1 place × 2, 2 places × 4, 3 places × 8). A right shift divides in the same way.

Device-free: give each student a strip of 8 boxes; they write 00010110 and physically slide the digits along.

01 · LEARN · WHEN SHIFTS GO WRONG

Bits that fall off are lost

▮ TERMINAL // shift_errors.txt

1  RIGHT 1  00010111 (23)   ->  00001011 (11)    23 / 2 = 11.5, 11 stored

2  LEFT 1   11000001 (193)  ->  10000010 (130)   193 x 2 = 386, 130 stored

Right shift: loss of precision

The 1 on the right falls off, so the .5 is lost. The answer is rounded down.

Left shift: a 1 falls off the left

The 128 bit is pushed out of the byte, so the result is wrong: the number has overflowed.

Click to reveal each line, then each explanation.

Line 1: 00010111 = 16 + 4 + 2 + 1 = 23. Right shift 1: 00001011 = 8 + 2 + 1 = 11. 23 ÷ 2 = 11.5, but only 11 can be stored: loss of precision.

Line 2: 11000001 = 128 + 64 + 1 = 193. Left shift 1: 10000010 = 128 + 2 = 130. 193 × 2 = 386, which needs 9 bits; the leftmost 1 is lost, so 130 is stored.

Exam phrase: "a right shift can cause a loss of precision because bits shifted off the right are lost".

Device-free: students predict each result on mini whiteboards before each click.

00001101 is shifted 2 places to the left. What is the result?

A

00000011

B

00011010

C

00110101

D

00110100

Answer: 00110100. 00001101 = 13. A left shift of 2 places multiplies by 4: 13 × 4 = 52, and 00110100 = 32 + 16 + 4 = 52.

Distractors: 00000011 (3) is a right shift of 2. 00011010 (26) is a left shift of only 1 place. 00110101 fills the gap with a 1 instead of 0s.

Device-free: students write the answer and the denary check on mini whiteboards. Image credit: Brecht Corbeel / Unsplash

01 · LEARN · HEXADECIMAL

Hexadecimal: base 16

Hex uses 16 digits: 0 to 9, then A to F for 10 to 15.

One hex digit stands for exactly one nibble (4 bits), so a byte is two hex digits: 11111111 = FF.

Why use it? It is shorter than binary, easier for people to read and remember, and fewer mistakes are made copying it. The computer still stores binary.

Seen in colour codes, MAC addresses and error codes.

Key term: hexadecimal (hex) = base 16, using the digits 0 to 9 and the letters A to F (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15).

Why it is used: it is a shorthand for binary. It is quicker to write, easier to read and remember, and less error-prone than long strings of 0s and 1s. It converts to and from binary easily because one hex digit = one nibble.

Misconception: computers do not store or process hex. Hex is only for people; inside the computer everything is still binary.

Examples: HTML colour #FF7AD9 (the pink on these slides) is three bytes in hex; MAC addresses such as 3C:52:82:1A:7F:A0 are written in hex.

Device-free: students write the definition and two reasons hex is used. Image credit: MJH SHIKDER / Unsplash

01 · LEARN · HEX DIGITS

Sixteen digits, sixteen nibbles

0

0000

= 0

1

0001

= 1

2

0010

= 2

3

0011

= 3

4

0100

= 4

5

0101

= 5

6

0110

= 6

7

0111

= 7

8

1000

= 8

9

1001

= 9

A

1010

= 10

B

1011

= 11

C

1100

= 12

D

1101

= 13

E

1110

= 14

F

1111

= 15

Pink = hex digit · white = nibble (4 bits) · blue = denary. Learn A to F: they are the new ones.

Each card shows a hex digit (pink), the nibble it stands for, and its denary value. A to F (highlighted) are the ones to learn: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

Checks: A = 1010 = 8 + 2. C = 1100 = 8 + 4. F = 1111 = 8 + 4 + 2 + 1.

Memory trick: A to F count on from 9, so F is the largest single hex digit (15).

Device-free: students copy the table; cover it and quiz each other on A to F.

01 · LEARN · BINARY AND HEX

Split the byte into two nibbles

▮ TERMINAL // hex_convert.txt

1  BINARY TO HEX  10111110

2    1011  |  1110

3      11  |    14

4       B  |     E   = BE

5  HEX TO BINARY  3C

6    3 = 0011,  C = 12 = 1100

7    = 00111100

Binary to hex

Split into two nibbles. Convert each nibble to one hex digit.

Hex to binary

Turn each hex digit into a 4-bit nibble. Keep the leading 0s.

Click to reveal each line.

Binary to hex: 10111110 splits into 1011 and 1110. 1011 = 8 + 2 + 1 = 11 = B. 1110 = 8 + 4 + 2 = 14 = E. Answer BE. Check: BE = 11 × 16 + 14 = 190, and 10111110 = 128 + 32 + 16 + 8 + 4 + 2 = 190.

Hex to binary: 3 = 0011 and C = 12 = 1100, so 3C = 00111100. Check: 3 × 16 + 12 = 60, and 32 + 16 + 8 + 4 = 60.

Misconception: writing 3 as 11 instead of 0011. Each hex digit must become exactly 4 bits.

Device-free: students convert 01101111 to hex (6F) and A5 to binary (10100101).

01 · LEARN · HEX AND DENARY

The left digit counts 16s

▮ TERMINAL // hex_denary.txt

1  HEX TO DENARY

2    2F = (2 x 16) + 15 = 47

3    FF = (15 x 16) + 15 = 255

4  DENARY TO HEX  200

5    200 / 16 = 12 remainder 8

6    12 = C, 8 = 8  = C8

7  CHECK (12 x 16) + 8 = 200

Two hex digits

Left digit × 16, plus the right digit.

00 to FF covers 0 to 255: exactly one byte.

Stuck? Go through binary: 200 = 11001000 = 1100 1000 = C8.

Click to reveal each line.

Hex to denary: the left digit is worth 16s, the right digit 1s. 2F = 2 × 16 + 15 = 32 + 15 = 47. FF = 15 × 16 + 15 = 240 + 15 = 255, the largest value in one byte.

Denary to hex: divide by 16. 200 ÷ 16 = 12 remainder 8 (12 × 16 = 192, 200 − 192 = 8). 12 = C, so 200 = C8.

Alternative route that many students find easier: denary to binary, then binary to hex. 200 = 11001000 (from lesson 4) = 1100 1000 = C8.

Device-free: students convert 3A to denary (3 × 16 + 10 = 58) and 100 to hex (6 × 16 = 96, remainder 4, so 64).

Drag each hex number to its denary value.

26

77

127

160





A0

1A

7F

4D

Answers: 1A = 1 × 16 + 10 = 26. 4D = 4 × 16 + 13 = 77. 7F = 7 × 16 + 15 = 127. A0 = 10 × 16 + 0 = 160.

Misconception: reading A0 as 10 + 0 = 10. The A is in the 16s column.

Device-free: write the four hex numbers on the board; students convert each on mini whiteboards.

Convert the binary number 11010011 into hexadecimal.

Answer: D3. Working: 11010011 splits into 1101 and 0011. 1101 = 8 + 4 + 1 = 13 = D. 0011 = 2 + 1 = 3. So D3.

Check: D3 = 13 × 16 + 3 = 211, and 11010011 = 128 + 64 + 16 + 2 + 1 = 211.

Answer matching ignores capitals, so d3 is accepted too.

Device-free: students write the answer with both nibbles shown.

1

Write the two hex digits side by side

2

Change any value from 10 to 15 into a letter from A to F

3

Split the 8-bit number into two nibbles of 4 bits

4

Work out the denary value of each nibble using 8, 4, 2, 1

Convert 8-bit binary to hexadecimal. Put the steps in order.

Correct order: split into two nibbles; denary value of each nibble (8 4 2 1); turn 10 to 15 into A to F; write the two digits side by side.

Example: 1010 1111 gives 10 and 15, which is A and F, so the answer is AF.

Device-free: students number the four steps, then use them on 0011 1100 (answer 3C).

Complete the key facts.

Adding two 8-bit numbers can give a result too big to store. This is an overflow error. A left shift of 1 place multiplies a number by 2. A right shift of 3 places divides by 8. Hexadecimal is base 16, and one hex digit represents a nibble.

overflow
multiplies
8
16
nibble
divides
6
byte
carry

Answers: overflow, multiplies, 8, 16, nibble.

A right shift of 3 places divides by 2 × 2 × 2 = 8. Distractors: divides, 6 (3 × 2, a common slip), byte (two hex digits), carry.

Device-free: read the sentences aloud with gaps; students write the missing words.

04 · EXAM · PRACTICE QUESTION

Exam practice (6 marks)

Amir's program works with the 8-bit numbers 01011010 and 00111100.

(a) Add the two numbers. Give your answer in 8-bit binary and show your working. [2]

(b) Convert your answer to hexadecimal. [2]

(c) 01011010 is shifted 2 places to the right. Give the result and state one problem with this shift. [2]

8

minute

00

second

8 minutes

Students answer in silence, in exam conditions, with the 8-minute timer. Then show the next slide.

Mark scheme. (a) 1 mark: working shows the carries. 1 mark: 10010110.

(b) 1 mark for each correct hex digit: 96. Follow through: award marks for correctly converting a wrong answer from (a).

(c) 1 mark: 00010110. 1 mark: loss of precision, e.g. 90 ÷ 4 = 22.5 but only 22 is stored, or the bits 10 on the right are lost.

Device-free: print or project the question; students answer on paper.

04 · EXAM · MODEL ANSWER

Model answer and working

▮ TERMINAL // model_answer.txt

1  (a)   0 1 0 1 1 0 1 0   (90)

2      + 0 0 1 1 1 1 0 0   (60)

3  carry 1 1 1 1 0 0 0 0

4        1 0 0 1 0 1 1 0   (150)

5  (b)   1001 = 9, 0110 = 6  = 96

6  (c)   00010110 (22)

7        90 / 4 = 22.5: precision lost

Common mistakes

Forgetting to add the carry into the next column.

Writing the nibbles the wrong way round (69).

Saying a right shift multiplies.

Click to reveal the working a line at a time; students mark their own answer in a different colour.

(a) Working from the right: 0 + 0 = 0; 1 + 0 = 1; 0 + 1 = 1; 1 + 1 = 0 carry 1; 1 + 1 + 1 = 1 carry 1; 0 + 1 + 1 = 0 carry 1; 1 + 0 + 1 = 0 carry 1; 0 + 0 + 1 = 1. Answer 10010110. Check: 90 + 60 = 150 = 128 + 16 + 4 + 2.

(b) 1001 = 9 and 0110 = 6, so 96. Check: 9 × 16 + 6 = 150.

(c) 01011010 shifted right 2 places = 00010110 = 22. 90 ÷ 4 = 22.5, so the result has lost precision (the two bits on the right, 10, fall off).

Device-free: read out the model answer; students mark their own work using the mark scheme on the previous slide's notes.

1

Binary addition and overflow

2

Binary shifts

3

Hexadecimal conversions

4

I am confident with all three

Which skill from today needs the most practice?

Exit poll. Revisit the three outcomes from the start of the lesson. Use the results to plan the starter for the next lesson.

Device-free: students hold up 1, 2, 3 or 4 fingers as they leave.

KEEP GOING

Practise beyond the lesson

Isaac Computer Science

Free lessons and questions on binary arithmetic and hexadecimal.

isaaccomputerscience.org

BBC Bitesize

GCSE Computer Science (OCR): data representation revision and tests.

bbc.co.uk/bitesize

OCR past papers

J277/01 papers and mark schemes: look for binary addition, shift and hex questions.

ocr.org.uk

Next lesson: characters, images and sound: ASCII, Unicode, resolution, colour depth and sample rate.

Point students to independent practice. Isaac Computer Science and BBC Bitesize are free. OCR publishes J277 past papers and mark schemes on its website.

Homework idea: convert your age, your house number and 200 into binary and into hex, then check each answer by converting it back to denary.

Device-free: students write down the three sites and the homework task.