Apply a binary shift

What is a Binary Shift?

A binary shift moves every bit in an 8-bit pattern left or right by a specified number of positions. AQA requires only the logical shift: every position vacated by the moving bits is filled with a 0, and any bit that moves beyond the 8-bit boundary is permanently lost.

Shifts have a precise mathematical effect. A left shift by n positions multiplies the value by 2n, and a right shift by n positions performs integer division by 2n. Any remainder from a right shift is simply discarded - no fractions are stored.

DirectionPositionsMathematical effect
Left1× 2
Left2× 4
Left3× 8
Right1÷ 2 (integer)
Right2÷ 4 (integer)
Right3÷ 8 (integer)

Worked Examples

Left Shift by 2

Shift 00001011 (11) left by 2. Every bit moves 2 positions to the left; two 0s fill the vacated positions on the right.

b7b6b5b4b3b2b1b0Decimal
Before0000101111
After0010110044

Yellow cells show the two zeros filled on the right. Result: 00101100 = 44. Check: 11 × 4 = 44 ✓

Right Shift by 2

Shift 10110111 (183) right by 2. Every bit moves 2 positions to the right; two 0s fill the left. The two rightmost bits are permanently discarded.

b7b6b5b4b3b2b1b0Decimal
Before10110111183
After0010110145

Red cells show the two discarded bits (both 1s - representing a remainder of 0.75). Yellow cells show the zeros filled on the left. Result: 00101101 = 45. Exact: 183 ÷ 4 = 45.75, but the remainder is dropped. Check: 183 ÷ 4 = 45 (integer) ✓

Left Shift with Overflow

Shift 01100000 (96) left by 2. The bit at b6 (value 64) would move to position b8 - beyond the 8-bit boundary - and is lost. This is called overflow.

b7b6b5b4b3b2b1b0Decimal
Before0110000096
After10000000128

The red bit (b6 = 1) would shift to b8 - lost. Only the bit at b5 (value 32) successfully shifts to b7, giving 10000000 = 128. Expected result: 96 × 4 = 384, but 384 exceeds 255 and cannot fit in 8 bits. The multiplication relationship breaks down whenever overflow occurs.

 Key Takeaways

  • A logical left shift by n positions moves all bits left, fills n zeros on the right, and multiplies the value by 2n.
  • A logical right shift by n positions moves all bits right, fills n zeros on the left, and integer-divides the value by 2n - any remainder is discarded.
  • Overflow occurs during a left shift when a 1-bit is pushed beyond b7; the multiplication result is incorrect because data has been permanently lost.
  • For AQA GCSE: numbers are always 8 bits, only logical shifts are required, and results are never expressed as fractions.