ELI5: Explain Like I'm 5

Logical shift

Hey kiddo, do you know what shifting is? It's like moving something to a different position. For example, let's say you have 5 marbles, and you want to move them one place to the left, so now, the first marble becomes empty and the second marble becomes the first. Logical shift is just like this, but instead of with marbles, we do it with bits.

Now, do you know what bits are? They are tiny little pieces of information that computers use to store data. Like marbles, but much smaller. Each bit can be either 0 or 1. When we shift bits, we move them left or right. Just like when we shifted the marbles.

Logical shift is one type of shift, which is very simple. When we shift to the left, we add a 0 to the right side. So if we have the number 1101, when we do a logical shift to the left, we move the bits one position to the left, which means we add a 0 to the right, and it becomes 11010.

But what if we shift to the right? When we shift to the right, we sometimes add a 0 and sometimes add a 1. If we want to keep the same number of bits, we add a 0. For example, if we have the number 1101, when we do the logical shift to the right, it becomes 0110. Did you see? We added a 0 to the left side.

But if we don't mind losing a bit, we can add a 1. For example, if we have the number 1101, and we do a logical shift to the right, and we want to lose the leftmost bit, we add a 1. So it becomes 0110. But now the leftmost bit is gone.

And that's all there is to it! Logical shift is just moving bits around by adding a 0 or a 1.