What you'll learn
Binary shifts are fundamental operations that move binary digits left or right within a register. This topic focuses on how logical shifts affect binary values and their denary equivalents, which is essential for understanding data manipulation in computer systems. You'll learn to perform shift operations and calculate their effects on numerical values.
Key terms and definitions
Binary shift — An operation that moves all bits in a binary number a specified number of positions to the left or right.
Logical left shift — A binary shift operation that moves all bits to the left by a specified number of positions, filling vacated positions on the right with zeros.
Logical right shift — A binary shift operation that moves all bits to the right by a specified number of positions, filling vacated positions on the left with zeros.
Register — A small, fast storage location within the CPU that holds binary data during processing operations.
Overflow — A condition that occurs when a calculation produces a result too large to be stored in the available number of bits.
Bit — A single binary digit, either 0 or 1, representing the smallest unit of data in computing.
Denary — The base-10 number system used in everyday mathematics (also called decimal).
Binary — The base-2 number system using only 0 and 1, which computers use to represent all data.
Core concepts
Understanding binary shifts
Binary shifts move every bit in a binary number either left or right by one or more positions. These operations are performed within registers of fixed size, typically 8 bits in IGCSE examples. When bits are shifted, new positions must be filled, and bits that move beyond the register boundaries are lost.
The key principle is that bits always move in the direction specified:
- Left shifts move bits towards the most significant bit (MSB)
- Right shifts move bits towards the least significant bit (LSB)
Vacated positions are always filled with 0 in logical shifts. This distinguishes them from arithmetic shifts, which are not covered at IGCSE level but may be encountered at A-level.
Logical left shift operations
A logical left shift moves all bits one position to the left. Each bit moves from position n to position n+1. The rightmost position (LSB) is filled with 0, and the leftmost bit (MSB) is lost if it moves beyond the register.
Effect on denary values:
- Each left shift by one position multiplies the denary value by 2
- A left shift by two positions multiplies the denary value by 4
- A left shift by n positions multiplies the denary value by 2^n
Example with 8-bit register:
Original: 0001 0110 (denary 22)
After 1 left shift: 0010 1100 (denary 44)
After 2 left shifts: 0101 1000 (denary 88)
The multiplication effect works because binary is base-2. Just as shifting a denary number left multiplies by 10 (e.g., 25 becomes 250), shifting a binary number left multiplies by 2.
Overflow consideration:
If a significant bit (a 1) is shifted out of the MSB position, overflow occurs and the result becomes incorrect. For example:
Original: 1000 0001 (denary 129)
After 1 left shift: 0000 0010 (denary 2, but should be 258)
The MSB (1) was lost, causing overflow. The actual result (258) cannot fit in 8 bits.
Logical right shift operations
A logical right shift moves all bits one position to the right. Each bit moves from position n to position n-1. The leftmost position (MSB) is filled with 0, and the rightmost bit (LSB) is lost.
Effect on denary values:
- Each right shift by one position divides the denary value by 2 (integer division)
- A right shift by two positions divides the denary value by 4
- A right shift by n positions divides the denary value by 2^n
The division is integer division, meaning any remainder is discarded. This happens because the fractional part (represented by the lost LSB) cannot be stored in integer binary representation.
Example with 8-bit register:
Original: 0101 1000 (denary 88)
After 1 right shift: 0010 1100 (denary 44)
After 2 right shifts: 0001 0110 (denary 22)
Loss of precision:
When the LSB contains a 1, shifting right discards this information:
Original: 0001 0111 (denary 23)
After 1 right shift: 0000 1011 (denary 11, not 11.5)
The bit representing 1 was lost, so 23 ÷ 2 = 11 (with remainder discarded).
Practical applications of binary shifts
Binary shifts are used in computing for several purposes:
Fast multiplication and division:
- Processors can shift bits much faster than performing full multiplication or division algorithms
- Multiplying by powers of 2 (2, 4, 8, 16, etc.) uses left shifts
- Dividing by powers of 2 uses right shifts
Graphics and image processing:
- Scaling image coordinates or dimensions
- Adjusting brightness values (dividing by 2 to darken)
Data compression:
- Packing multiple values into single bytes
- Extracting specific bits from packed data
Network protocols:
- Manipulating IP addresses and subnet masks
- Processing packet headers
Working with different register sizes
While 8-bit examples are common in IGCSE, the principles apply to any register size. The CIE specification may use 4-bit, 8-bit, or 16-bit examples.
4-bit example:
Original: 1010 (denary 10)
Left shift 1: 0100 (denary 4, overflow occurred)
Right shift 1: 0101 (denary 5)
16-bit example:
Original: 0000 0000 1111 0000 (denary 240)
Left shift 2: 0000 0011 1100 0000 (denary 960)
Right shift 2: 0000 0000 0011 1100 (denary 60)
The principle remains consistent: left shifts multiply by 2^n, right shifts divide by 2^n, with zeros filling vacated positions.
Combining multiple shifts
Multiple shift operations can be performed sequentially:
Original: 0001 1000 (denary 24)
Left shift 2 then right shift 1:
- After left shift 2:
0110 0000(denary 96) - After right shift 1:
0011 0000(denary 48)
The net effect is multiplying by 4 then dividing by 2, giving a final multiplication by 2.
However, if a left shift causes overflow, subsequent right shifts cannot recover the lost data:
Original: 1100 0000 (denary 192)
Left shift 1 then right shift 1:
- After left shift 1:
1000 0000(denary 128, overflow lost the second MSB) - After right shift 1:
0100 0000(denary 64, not 192)
Worked examples
Example 1: Performing a logical left shift
Question: The 8-bit binary number 0011 0101 is stored in a register. Perform a logical left shift by 2 positions and give the result in both binary and denary. [3 marks]
Solution:
Original value: 0011 0101
After 1st left shift: 0110 1010
After 2nd left shift: 1101 0100
Binary result: 1101 0100 [1 mark]
Denary conversion: 128 + 64 + 16 + 4 = 212 [1 mark]
Alternative approach: Original denary value = 32 + 16 + 4 + 1 = 53 Left shift by 2 multiplies by 4: 53 × 4 = 212 [1 mark for correct method and answer]
Example 2: Performing a logical right shift with precision loss
Question: A register contains the binary value 0010 1011 (denary 43).
(a) Perform a logical right shift by 1 position. Give your answer in binary and denary. [2 marks]
(b) Explain why the denary result is not exactly half of the original value. [2 marks]
Solution:
(a) Original: 0010 1011
After right shift: 0001 0101
Binary answer: 0001 0101 [1 mark]
Denary answer: 16 + 4 + 1 = 21 [1 mark]
(b) The LSB contained a 1, which represented a value of 1 in denary [1 mark]. When this bit was shifted out of the register, this value was lost, so the result is 21 instead of 21.5 (integer division) [1 mark].
Example 3: Identifying overflow in left shifts
Question: A programmer stores the value 1011 0110 in an 8-bit register and performs a logical left shift by 1 position.
(a) Give the binary result after the shift. [1 mark]
(b) Calculate the denary value before and after the shift. [2 marks]
(c) Explain whether overflow has occurred. [2 marks]
Solution:
(a) After left shift: 0110 1100 [1 mark]
(b) Before shift: 128 + 32 + 16 + 4 + 2 = 182 [1 mark]
After shift: 64 + 32 + 8 + 4 = 108 [1 mark]
(c) Overflow has occurred [1 mark]. The MSB (1) was shifted out of the register, and the expected result (182 × 2 = 364) cannot be stored in 8 bits. The maximum 8-bit value is 255, so the result is incorrect [1 mark].
Common mistakes and how to avoid them
Forgetting to fill vacated positions with zeros: Always remember that in logical shifts, new positions are filled with 0, not with copies of neighbouring bits. Draw out each step if needed.
Confusing left and right shift directions: Left shifts move towards the MSB (most significant bit, on the left) and multiply by 2. Right shifts move towards the LSB (least significant bit, on the right) and divide by 2. Visualise the direction physically.
Incorrectly calculating the multiplication/division effect: A shift by n positions multiplies or divides by 2^n, not by n. For example, 3 left shifts multiply by 8 (2^3), not by 3.
Not recognising overflow: If the MSB is 1 before a left shift, check whether it will be shifted out. If so, overflow occurs and the result is incorrect. Always verify that your answer makes mathematical sense.
Mixing up the bit positions during multi-step shifts: When performing multiple shifts, work step-by-step and write out the intermediate results. Attempting to shift by multiple positions in one mental step often leads to errors.
Forgetting that right shifts perform integer division: When a right shift would create a fractional result (e.g., 23 ÷ 2 = 11.5), the fractional part is lost. The result is always a whole number rounded down.
Exam technique for binary shifts
Command word "Perform": You must show the binary result after the shift operation. Give your answer in the format requested (usually binary, sometimes also denary). Working is often required for full marks.
Command word "Explain": Provide reasons for what happens during the shift. Mention specific details like "the MSB is lost" or "vacated positions are filled with 0" to demonstrate understanding beyond just performing calculations.
Mark allocation guidance: Questions worth 1-2 marks typically require the final answer only. Questions worth 3+ marks usually require working or explanation. Show each shift step when performing multiple shifts.
Common question patterns: Expect questions combining binary shifts with denary conversion, overflow identification, or practical applications. Practise converting between binary and denary efficiently to save time.
Quick revision summary
Binary shifts move bits left or right within a register. Logical left shifts move bits towards the MSB, filling vacated right positions with 0, and multiply the denary value by 2^n where n is the number of positions shifted. Logical right shifts move bits towards the LSB, filling vacated left positions with 0, and divide the denary value by 2^n using integer division. Overflow occurs when significant bits are lost during left shifts. Right shifts may lose precision when the LSB is 1. Both operations are used for efficient multiplication and division by powers of 2.