What Is a Logical Binary Shift?
A logical binary shift is the process of moving every bit in a binary number to the left or to the right by a specified number of places. It is one of the simplest operations a computer’s processor can perform, and it has a remarkably useful side effect: it multiplies or divides the number by a power of 2.
Here is the core idea in two sentences:
- A left shift by n places moves every bit n positions to the left. The empty spaces on the right are filled with 0s. This has the effect of multiplying the number by 2n.
- A right shift by n places moves every bit n positions to the right. The empty spaces on the left are filled with 0s. This has the effect of performing an integer division (whole-number division) by 2n.
In both cases, any bits that are pushed off the end of the register are permanently lost. They do not wrap around — they simply disappear. This is an important detail that catches many students out in exams.
Think of it like a row of eight boxes on a conveyor belt. If you push the belt to the left by one position, everything moves one box to the left, a zero drops into the empty box on the right, and whatever was in the leftmost box falls off the edge and is gone forever.
Worked Examples
Let us work through several examples so you can see exactly what happens to the bits during a shift. Pay close attention to where the 0s are inserted and where bits fall off.
Example 1: Left Shift by 1
Starting number: 00001010 (10 in denary). Shift all bits one place to the left.
Before: 0 0 0 0 1 0 1 0 (10)
← ← ← ← ← ← ← ← shift left by 1
After: 0 0 0 1 0 1 0 0 (20)
^
0 fills in
Result: 10 × 2 = 20 ✓
Every bit moved one position to the left. A 0 filled the empty space on the right. The leftmost bit (0) fell off, but since it was already 0 this caused no problem. The denary value doubled from 10 to 20.
Example 2: Left Shift by 2
Starting number: 00000110 (6 in denary). Shift all bits two places to the left.
Before: 0 0 0 0 0 1 1 0 (6)
← ← ← ← ← ← ← ← shift left by 2
After: 0 0 0 1 1 0 0 0 (24)
^ ^
0s fill in
Result: 6 × 4 = 24 ✓
(Left shift by 2 = multiply by 2² = multiply by 4)
Every bit jumped two positions to the left. Two 0s filled in on the right. The two leftmost bits (both 0) fell off harmlessly. The denary value went from 6 to 24 — that is 6 × 4, exactly as the rule predicts.
Example 3: Right Shift by 1
Starting number: 00010100 (20 in denary). Shift all bits one place to the right.
Before: 0 0 0 1 0 1 0 0 (20)
→ → → → → → → → shift right by 1
After: 0 0 0 0 1 0 1 0 (10)
^
0 fills in
Result: 20 ÷ 2 = 10 ✓
Every bit moved one position to the right. A 0 filled in on the left. The rightmost bit (0) fell off, and since it was 0 no data was lost. The denary value halved from 20 to 10.
Example 4: Right Shift by 3
Starting number: 01101000 (104 in denary). Shift all bits three places to the right.
Before: 0 1 1 0 1 0 0 0 (104)
→ → → → → → → → shift right by 3
After: 0 0 0 0 1 1 0 1 (13)
^ ^ ^
0s fill in
Result: 104 ÷ 8 = 13 ✓
(Right shift by 3 = divide by 2³ = divide by 8)
Every bit moved three positions to the right. Three 0s filled in on the left. Three bits (0, 0, 0) fell off the right-hand side — all were 0 in this case, so no data was lost. The denary value went from 104 to 13 — that is 104 ÷ 8, exactly as the rule predicts.
When Things Go Wrong: Data Loss from a Left Shift
Now let us see what happens when a left shift pushes a significant bit (a 1) off the left-hand edge.
Before: 1 1 0 0 0 0 0 0 (192)
← ← ← ← ← ← ← ← shift left by 1
After: 1 0 0 0 0 0 0 0 (128)
^ ^
1 fell off! 0 fills in
Expected: 192 × 2 = 384
Actual: 128 ✗ WRONG!
The answer 384 does not fit in 8 bits.
The leftmost 1 was pushed off the edge and lost. The mathematically correct answer is 192 × 2 = 384, but 384 requires 9 bits to represent (110000000). Since we only have 8 bits, the 9th bit is gone and we are left with 10000000 = 128 — a completely wrong result. This is overflow caused by a left shift.
- Left shift 00000101 (5) by 2. What do you get? (Expected: 5 × 4 = 20 = 00010100)
- Right shift 00110000 (48) by 2. What do you get? (Expected: 48 ÷ 4 = 12 = 00001100)
- Left shift 01100000 (96) by 2. Does data loss occur? (Yes! 96 × 4 = 384, which overflows 8 bits)
- Right shift 00000111 (7) by 1. What do you get? Is the result exactly 3.5? (You get 3 — the 0.5 is lost)
x * 8, a programmer might write x << 3 (left shift by 3), and the CPU executes it in a single clock cycle rather than several.
Shifts and Data Loss
Data loss is the most important pitfall to understand when working with binary shifts. There are two situations where it occurs, and both are commonly tested in exams.
1. Left Shift Overflow
When you shift bits to the left, the leftmost bits are pushed off the edge of the register. If any of those lost bits were 1s, the result will be incorrect. This is essentially the same kind of overflow error you learned about in binary addition — the correct answer simply does not fit in the available number of bits.
For example, in 8 bits, the number 192 (11000000) cannot be doubled by a left shift because 384 needs 9 bits. Any number larger than 127 will overflow if left-shifted by 1 in an 8-bit system. More generally, a left shift by n will overflow if the original number is greater than 255 ÷ 2n (for 8-bit unsigned numbers).
2. Right Shift Precision Loss
When you shift bits to the right, the rightmost bits fall off. If any of them were 1s, information is lost. This most commonly happens when you right-shift an odd number.
Consider the number 7 (00000111). If we right-shift by 1:
Before: 0 0 0 0 0 1 1 1 (7)
→ → → → → → → → shift right by 1
After: 0 0 0 0 0 0 1 1 (3)
^
1 fell off!
Expected: 7 ÷ 2 = 3.5
Actual: 3 (the .5 is lost)
This is INTEGER division — the remainder is discarded.
The mathematically correct answer is 3.5, but binary integers cannot represent fractions. The rightmost 1 fell off and was lost, so the computer stores 3. This is not an error in the way overflow is — it is the expected behaviour of integer division — but it does mean that right shifting is only an exact division when the number is evenly divisible by 2n.
Summary of Data Loss Rules
| Shift Direction | What Can Go Wrong | When It Happens |
|---|---|---|
| Left | Overflow — significant 1s pushed off the left | When the result exceeds the maximum value for the bit width (e.g. > 255 for 8 bits) |
| Right | Precision loss — significant 1s fall off the right | When the original number is odd, or more generally when any of the discarded bits are 1 |
Interactive Exercise 1: Left Shift Practice
Perform the left shift shown below. Enter the resulting 8-bit binary number.
Interactive Exercise 2: Right Shift Practice
Perform the right shift shown below. Enter the resulting 8-bit binary number.
Test Yourself
Click on each question to reveal the answer. Try to work it out on paper first — draw out the 8 boxes and physically move the bits!
Answer:
Before: 0 0 0 1 0 1 1 0 (22)
After: 0 0 1 0 1 1 0 0 (44)
Result: 00101100 = 44. Check: 22 × 2 = 44. Correct — no data loss.
Answer:
Before: 0 1 1 0 0 1 0 0 (100)
After: 0 0 0 1 1 0 0 1 (25)
Result: 00011001 = 25. Check: 100 ÷ 4 = 25. Correct — no data loss because the two rightmost bits were both 0.
Answer:
Before: 0 0 0 0 0 1 0 1 (5)
After: 0 0 1 0 1 0 0 0 (40)
Result: 00101000 = 40. A left shift by 3 is the same as multiplying by 23 = 8. Check: 5 × 8 = 40. Correct.
Answer:
Before: 0 0 0 0 1 0 1 1 (11)
After: 0 0 0 0 0 1 0 1 (5)
Result: 00000101 = 5. The mathematically correct answer is 11 ÷ 2 = 5.5, but the rightmost 1-bit fell off. The computer gives 5 — the 0.5 is lost. This is precision loss due to integer division.
Answer:
Before: 0 1 1 0 0 0 0 0 (96)
After: 1 0 0 0 0 0 0 0 (128)
Expected: 96 × 4 = 384
Actual: 128 ✗ WRONG!
The correct answer is 96 × 4 = 384, but 384 cannot fit in 8 bits (it would need 9 bits: 110000000). The leftmost 1 was shifted out and lost, leaving 10000000 = 128. This is overflow — the result is incorrect because significant bits were lost during the shift.
Answer: Binary is a base-2 number system, where each column has a place value that is twice the column to its right (1, 2, 4, 8, 16, 32, 64, 128). When you shift a bit one place to the left, you move it from its current column into the column with double the place value. For example, a 1 in the 8s column moves to the 16s column — its value doubles. Since every bit doubles in value, the entire number doubles. Shifting by 2 places doubles twice (× 4), by 3 places doubles three times (× 8), and so on. In general, shifting left by n places multiplies by 2n.
Answer: A left shift by 4 moves all bits four places to the left, meaning the four leftmost bits will be shifted out and lost. If any of those four bits are 1s, the result will be incorrect due to overflow. Specifically, for an 8-bit unsigned number, the shift will only give the correct answer if the original number is 15 or less (i.e. 255 ÷ 16 = 15, rounded down). Any value from 16 upwards, when multiplied by 16, exceeds 255 and cannot fit in 8 bits. For example, 16 × 16 = 256, which overflows. The programmer should ensure the variable’s value is small enough that the result fits within the bit width, or use a larger data type.
Key Vocabulary
Make sure you know all of these terms for your exam:
| Term | Definition |
|---|---|
| Binary Shift | The process of moving all bits in a binary number a specified number of places to the left or right. Empty positions are filled with 0s, and bits that move beyond the register are lost. |
| Left Shift | A binary shift that moves all bits to the left by n places. Equivalent to multiplying the number by 2n. Zeros fill in on the right-hand side. |
| Right Shift | A binary shift that moves all bits to the right by n places. Equivalent to integer division by 2n. Zeros fill in on the left-hand side. |
| Logical Shift | A type of binary shift where the vacated positions are always filled with 0s, regardless of the direction of the shift. This is the type of shift studied at GCSE level (as opposed to arithmetic shifts, which preserve the sign bit). |
| Data Loss | The permanent loss of information when bits containing 1s are shifted off the edge of the register. This causes the result to be inaccurate. It can occur in both left shifts (overflow) and right shifts (precision loss). |
| Overflow | An error that occurs when the result of an operation is too large to fit in the available number of bits. In the context of shifts, overflow happens when a left shift pushes significant 1-bits off the left-hand end of the register. |
Exam Tips
Past Paper Questions
Try these exam-style questions, then click to reveal the mark scheme answer.
Perform a left shift of 2 places on the binary number 00010110. State the denary value before and after the shift. [3] marks
Mark scheme:
- Before: 00010110 = 22 in denary (1)
- After shift: 01011000 (1)
- = 88 in denary (multiplied by 4) (1)
Explain the effect of a right shift of 1 place on a binary number. [2] marks
Mark scheme:
- Each bit moves one position to the right / the rightmost bit is lost (1)
- The value is halved / divided by 2 (integer division) (1)
A binary number has a denary value of 40. What will its denary value be after a left shift of 3 places? [1] mark
Mark scheme:
320 (40 × 2³ = 40 × 8 = 320) (1)
Why Binary Shifts Matter
Binary shifts might seem like a simple mechanical process, but they are fundamental to how computers work at the hardware level. Here is why they matter beyond the exam:
- CPU optimisation: Modern compilers automatically convert multiplications and divisions by powers of 2 into shift operations because shifts are the fastest operations a processor can perform — often completing in a single clock cycle. When you write
score * 2in your code, the compiler may silently turn it into a left shift by 1. - Graphics and games: Game engines and graphics processors use shifts extensively. For example, pixel colour values are packed into 32-bit integers, and shifts are used to extract or combine the red, green, blue, and alpha (transparency) channels. Scrolling a screen, zooming an image, and blending colours all rely on shift operations under the hood.
- Networking: IP addresses and subnet masks are manipulated using shifts and bitwise operations. When a router determines whether a packet belongs to a particular network, it uses shifts to isolate the network portion of the address.
- Embedded systems: In microcontrollers (like those in washing machines, car engines, and medical devices), memory and processing power are extremely limited. Shifts allow programmers to perform multiplication and division without needing the full multiplication circuitry, saving both time and chip space.
- Cryptography: Encryption algorithms like AES and SHA use combinations of shifts, rotations, and bitwise operations to scramble data securely.
Understanding shifts gives you a deeper insight into how computers think at the most fundamental level. Every multiplication, every pixel drawn on screen, and every encrypted message you send is built upon these simple bit-moving operations.
Video Resources
Further Reading
- BBC Bitesize — Binary Shifts — Clear explanations of left and right shifts with practice questions
- BBC Bitesize — Edexcel GCSE Computer Science — Full specification coverage for data representation including binary shifts
- GCSE Topic 2: Data Representation — Interactive revision tools covering binary shifts and related topics