Community resourceWorksheet
OCR H446 1.4.1 Bitwise shifts and masks
Part 8 of 11 · H446 1.4.1 · Data types
A status byte holding eight independent permission flags is the setting for the shift and mask content of H446 1.4.1. Shifts move every bit at a fixed width while masks select particular positions, and OCR credits the calculated result and the purpose of the operation separately, so students are asked for both each time.
Students will:
- apply logical left and right shifts at a fixed width, tracking discarded and inserted bits
- state the multiplication or division effect of a shift and when that effect breaks down
- choose between AND, OR and XOR to test, set, clear or toggle bits
- design 8-bit masks for a stated purpose and explain why unselected bits are unchanged
- complete a Python function that toggles the bits identified by a mask
Inside: 8 explanation cells, 2 fill-in-the-blanks cells, 2 written answers, 1 Python task and 2 number answers. 32 marks, about 45 to 55 minutes.
Series: H446 1.4.1 · Data types, part 8 of 11.
Shared by Coding PathwayVerified teacher
- 15 cells
- About 45 minutes
- CC BY-SA 4.0
- Shared 31 Aug 2026
- Updated 3 Sept 2026
Preview
The whole resource, exactly as a class sees it. Answers and marking are held back.
Bitwise shifts and masks
A status byte stores eight independent permission flags. Shifts reposition every bit; masks select particular bit positions for a purpose.
By the end, you will be able to
- apply logical shifts at a fixed width
- state the unsigned power-of-two effect with its limits
- choose AND, OR or XOR to test, clear, set or toggle
- separate a computed result from the mask’s purpose
Reactivate: AND is 1 only when both input bits are 1; OR needs at least one 1; XOR needs different bits.
Logical shifts
A logical left shift moves every bit left, discards any bit that leaves the fixed width, and inserts 0 on the right. A logical right shift does the reverse and inserts 0 on the left. Without discarded 1s, these correspond to multiplication or integer division by powers of two for unsigned values.
Worked contrast: 00101100 shifted left once becomes 01011000, so 44 becomes 88. But 10110000 shifted left once becomes 01100000: the leading 1 is discarded, so 176 becomes 96 rather than 352. Always state the fixed width and check whether a 1 leaves it before claiming an exact power-of-two effect.
Worked model: follow the moving bits
10110010 shifted left once becomes 01100100. The original leading 1 is discarded and 0 enters on the right. As an unsigned value, 178 × 2 would be 356, which does not fit in eight bits; the stored result is therefore not the full mathematical product.
Guided routine: draw an arrow → cross out the leaving bit → insert 0 → only then interpret the denary effect.
Apply each two-place logical left shift to an 8-bit value and state its denary effect.
a)Apply a logical shift left of 2 places to 11010011.
b)Apply a logical shift left of 2 places to 01001000.
c)Apply a logical shift left of 2 places to 10110000.
Apply each one-place logical right shift to an 8-bit value and state its denary effect.
a)Apply a logical shift right of 1 place to 10010101.
b)Apply a logical shift right of 1 place to 10110111.
c)Apply a logical shift right of 1 place to 11001111.
Choose the operation
| Purpose for selected bit(s) | Operation and mask pattern |
|---|---|
| Test/extract | AND with 1 where bits should be kept |
| Set to 1 | OR with 1 where bits should be set |
| Clear to 0 | AND with 0 where bits should be cleared |
| Toggle | XOR with 1 where bits should change |
Unselected mask positions use the identity value for the operation.
Worked mask: applying 10110110 AND 00001111 produces 00000110. The four upper bits are cleared because the mask contains 0 there; the four lower bits are retained because the mask contains 1.
Worked mask: test the lower nibble
value 10110110
mask 00001111
AND 00000110
The calculation result is 00000110. The purpose is to clear the upper four positions while retaining/extracting the lower four. OCR can award these separately.
To design a mask, mark the target positions first. Then choose the operation and place its active value there: AND 1 to keep, OR 1 to set, XOR 1 to toggle.
- AND
- OR
- XOR
- NOT
Apply masks in Python
Complete the function. The mask identifies bits to toggle. Return the updated integer; the checks use values from 0 to 255.
def toggle_flags(status, mask):
# Return status with every selected bit toggled.
passDesign three 8-bit masks for a status byte: (a) set bit 5 to 1, (b) clear bit 2 to 0, and (c) toggle bits 1 and 0. State the operation used with each mask and explain why unselected bits are unchanged.
Number bits from 7 on the left to 0 on the right. Use the operation's identity value in unselected positions.
Students type their answer here.
The byte 10110110 is ANDed with the mask 00001111. State the 8-bit result and explain the purpose of this mask.
The result and its purpose earn separate credit.
Students type their answer here.
Closed-book checkpoint
Complete each sentence from memory. There is no answer bank and correctness is held for teacher review.
Retrieval check
Describe one shift by tracking discarded and inserted bits. Then design masks to test, set and toggle bit 2, explaining the purpose of each.