A logical shift is like moving marbles from one side of a box to the other, it changes where things are, but doesn’t add or remove anything new.
Imagine you have a row of 8 marbles in a box. Each marble can be either red (which means 1) or blue (which means 0). When you do a logical shift, you're like a kid who moves all the marbles to one side, and adds empty spaces on the other, just like when you push your toys to one end of the bed.
Like moving toys
If you have red, blue, blue, red, blue, blue, blue, blue (which is 10010000 in binary) and you do a logical shift to the right, it's like pushing all the marbles to the right side of the box. You add empty spaces on the left, so it becomes 01001000.
If you do a logical shift to the left, it’s like pushing the marbles to the left, and adding empty spaces on the right, turning 10010000 into 100100000 (but only if there's room in the box).
This is how computers move numbers around when they're doing math or working with bits, it’s just a simple, fun way of moving things around!
Examples
- Shifting the bits of a number to the left or right, like moving marbles in a line.
- A logical shift moves bits out of a binary number, like sliding pieces off a puzzle.
Ask a question
See also
- What are arithmetic shifts?
- Who is Register Shifts?
- Why Do Computers Get Hot When They Work?
- What is "Hello, World!"?
- What are binary interactions?