Binary addition, logical shifts and deliberate overflow models
By UK GCSE Computer Science · independent study · myAudience

Original AI-generated teaching raster via built-in image_gen; author inspected 2026-10-04. · Generated project artwork; no copied exam or publisher illustration. Independent rights/publication review pending.
Binary addition, logical shifts and deliberate overflow models
Binary addition uses the same place-value principle as decimal addition with base two. In a column 0+0 gives 0, 0+1 gives 1, and 1+1 gives 0 with carry 1. A sum of three ones gives 1 with carry 1 into the next column. Entry skills are eight-bit weights and integer arithmetic. addition questions use at most three eight-bit inputs, no more than three ones in a column and answers no wider than eight bits, without carrying beyond the eighth. We teach within that bound first, then explicitly extend the discussion to overflow because programs and storage formats still need a policy.
For 00101101 plus 00010011, the low four bits 1101+0011 produce 0000 with a carry into the next group. The high group 0010+0001 plus that carry gives 0100. Result 01000000 is 64, matching 45+19. When adding three numbers, account for each incoming carry rather than treating a whole nibble as one decimal digit. An independent decimal check is useful, but showing only the decimal sum does not explain the binary procedure.
A logical left shift inserts zeroes at the right and discards bits leaving the fixed-width left boundary; a logical right shift inserts zeroes at the left and discards rightmost bits. For unsigned values, shifting left by one multiplies by two only when no significant bit is discarded. 00101101 becomes 01011010, or 90. Shifting right by one yields 00010110, or 22, which is floor division of 45 by two, not 22.5. No fractional representation is needed by this specification. A shift is a representation operation under a stated width, not an unconditional arithmetic identity.
The lower panel in the generated raster shows 11111111+1 producing nine bits. This is an extension beyond the prescribed addition question bounds. Retaining only the low eight bits gives zero, but the mathematical sum and ordinary Python integer sum are 256. An application may reject overflow, retain a carry or wrap modulo 256. Our add_byte returns low bits and an overflow flag, so it makes the information loss visible. A packet length or safety counter should not silently wrap just because a demonstration can model it.
The function checks exact integers and inclusive byte limits, avoiding accidental acceptance of Booleans. Python's & 255 masks low bits; >> and << operate on integers, so the mask is what imposes our eight-bit width. Negative Python integers behave differently under shifts and are outside this unsigned model. The transfer asks you to show both the mathematical value and the stored value, then evaluate a policy choice instead of treating every bit operation as harmless arithmetic.
Runnable original Python 3 example (also saved verbatim in examples for CLI execution):
```python
def require_byte(value):
if type(value) is not int or not 0 <= value <= 255:
raise ValueError("unsigned byte required")
def add_byte(a, b):
"""Return (low eight bits, overflow); explicit wrap model, not safe default."""
require_byte(a)
require_byte(b)
total = a + b
return total & 255, total > 255
def shift_left_byte(value, places):
require_byte(value)
if type(places) is not int or not 0 <= places <= 8:
raise ValueError("shift count outside 0..8")
return (value << places) & 255
assert add_byte(45, 19) == (64, False)
assert add_byte(255, 1) == (0, True)
assert shift_left_byte(45, 1) == 90
assert shift_left_byte(200, 1) == 144
assert 45 >> 1 == 22
```
Worked example: Show the mathematical and eight-bit logical left-shift values for 200 shifted once.
200 is 11001000.
Mathematical doubling gives 400, needing nine bits.
Discard the leftmost outgoing 1 and append 0: 10010000 is 144.
Answer: 400 mathematically; 144 in the fixed-width shift model.
Check your understanding: Transfer: an eight-bit occupancy counter at 250 receives 10 arrivals and then 4 departures. Compare wrapping, saturation and rejection policies, and identify a safer response for a capacity limit of 255.
Answer: True arithmetic occupancy is 256 after both changes, with an intermediate 260. Wrapping yields 4 then 0 and misrepresents occupancy. Saturation gives 255 then 251, losing five arrivals. Rejection can refuse the arrival update and flag that the format/capacity is insufficient; a wider counter can preserve actual counts if observations must be recorded.
Why: No lossy policy is automatically safe. If the capacity is physical, reject or alert before accepting arrivals; if the counter records observed occupancy, preserve the observation in a wider format and flag a violation. State the application contract rather than choosing wrap because it is easy.