Unable to open this exercise
A logical binary shift moves all bits in a binary register a specified number of positions to the left or right. Vacated bit positions are always filled with zeros ($0$).
Learning Objectives
- Perform logical binary left shifts and right shifts on positive 8-bit integers.
- Determine the mathematical effect of logical shifts (multiplication and integer division by powers of 2).
- Identify precision loss and overflow resulting from bit shifts.
Core Syllabus Theory
1. What is a Logical Shift?
In a computer processor, registers frequently need to multiply or divide integers rapidly. Rather than executing complex arithmetic multiplication algorithms, the CPU can simply shift bits along the register.
- Logical Left Shift: Bits move to the left. Vacated positions on the right are filled with 0s.
- Logical Right Shift: Bits move to the right. Vacated positions on the left are filled with 0s.
2. Logical Left Shift (Multiplication by $2^n$)
Each single logical shift to the left multiplies the integer value by 2. Shifting $n$ places to the left multiplies the number by $2^n$:
Shift Distance | Multiplier ($2^n$) | Example Starting Value | Shifted Value |
|---|---|---|---|
Left 1 place | $\times 2^1 = 2$ | $00000101_2 \ (5_{10})$ | $00001010_2 \ (10_{10})$ |
Left 2 places | $\times 2^2 = 4$ | $00000101_2 \ (5_{10})$ | $00010100_2 \ (20_{10})$ |
Left 3 places | $\times 2^3 = 8$ | $00000101_2 \ (5_{10})$ | $00101000_2 \ (40_{10})$ |
Overflow During Left Shifts
If any $1$ is shifted out of the Most Significant Bit (MSB), an overflow error occurs because the resulting value exceeds the 8-bit register capacity ($255_{10}$). The most significant information is lost, leaving an incorrect value in the register.
3. Logical Right Shift (Integer Division by $2^n$)
Each single logical shift to the right performs integer division by 2 (discarding any fractional remainder). Shifting $n$ places to the right divides the number by $2^n$:
Shift Distance | Divisor ($2^n$) | Example Starting Value | Shifted Value |
|---|---|---|---|
Right 1 place | $\div 2^1 = 2$ | $00101000_2 \ (40_{10})$ | $00010100_2 \ (20_{10})$ |
Right 2 places | $\div 2^2 = 4$ | $00101000_2 \ (40_{10})$ | $00001010_2 \ (10_{10})$ |
Right 3 places | $\div 2^3 = 8$ | $00101000_2 \ (40_{10})$ | $00000101_2 \ (5_{10})$ |
Precision Loss During Right Shifts
When an odd number is shifted right, the Least Significant Bit (LSB) contains a $1$. When shifted right, this bit falls off the end of the register and is discarded. For example, shifting $00001101_2$ ($13_{10}$) right by 1 gives $00000110_2$ ($6_{10}$). The fractional part ($.5$) is permanently lost, causing precision loss.
Exam Tips & Common Pitfalls
Note: Direction Matters: Remember: Left = Larger (multiplication by $2^n$). Right = Reduce (division by $2^n$). Always Pad to 8 Bits: In Cambridge exam answers, write full 8-bit binary bytes showing all leading and trailing zeros.
Key Terminology Glossary
- Logical Shift: An operation that moves all bits in a register left or right, filling empty positions with 0.
- Vacated Bit: A bit position that becomes empty following a shift operation and is replenished with 0.
- Precision Loss: The loss of fractional numerical detail when bits shifted out of the LSB are discarded.
- Overflow: When bits shifted out of the MSB cause the number to exceed the storage capacity of the register.
Written practice and self-review
An 8-bit register holds the binary pattern 00001101 (denary 13). A programmer performs a logical binary shift of 1 place to the right. Explain what happens to the least significant bit, state the resulting binary pattern and denary value, and explain why this causes precision loss.
Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.
AI Socratic Tutor
Need guidance? Ask a question or use the hint below.
AI Socratic Tutor is an All-Access Benefit
Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.
You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.
Application: Check the reasoning
Application: Check the reasoning
- Shift unsigned 00010110 left by two places (eight bits): [Space 1]
- Shift unsigned 00010111 right by one place (eight bits): [Space 2]
- Does shifting 10000000 left once lose a 1: yes or no? [Space 3]
Sign in or create a free account to test your solution and track XP.