A-level Computer Science revision · Data representation

Shifts, masks and character sets

The idea

A logical shift moves bits left or right, filling with zeros: shifting left by 1 doubles an unsigned value; right by 1 halves it (integer division). Masks use AND to clear bits, OR to set bits and XOR to toggle bits. ASCII uses 7 bits (128 characters); Unicode uses more bits to represent characters from all languages.

  1. Shift left n: multiply by 2ⁿ. Shift right n: divide by 2ⁿ.
  2. AND with 0 clears; OR with 1 sets; XOR with 1 flips.
  3. ASCII vs Unicode: number of characters.

Watch out Bits shifted off the end are lost, which can change the value unexpectedly.

See it worked

Worked example

Shift 0001 0110 left by 2 places.

  1. 0001 0110 = 22.
  2. Left 2: 0101 1000.
  3. = 88, which is 22 × 4.

Answer 0101 1000 (88)

Your turn

Question 12 marks

What is 0110 1100 after a logical right shift of 2 places? Give the answer in denary.

Question 21 mark

Which operation with mask 0000 1111 keeps the right four bits and clears the left four?

Choose one
Question 31 mark

Why was Unicode introduced?

Choose one

A-level Computer Science Pro, OCR H446

A-level Computer Science Pro

£119 once

Price rises to £199 on 1 January. Save £80 by joining before then.

At least 12 months of access

By paying you agree to our Terms and get access straight away, which ends your 14-day cancellation right.

No VAT is charged.

Independent practice for OCR A-level Computer Science (H446), not endorsed by OCR.

Privacy · Terms