 What's up guys, my name is Michael and welcome to my YouTube channel. Today we are going to just do a fast video about just bit shifting. So about shifting left and shifting right. So let's say I have a number of five base 10 and I converted to binary. So the bits are 101, right? You could actually append a lot of zeros in front of it, right? You could append multiple, but let's just keep it like this. Okay. So this is five in binary. Now what happens if I shift five to the left? So the thing is that if you shift to the left, what happens to the bit? Well, all the bits get moved down by one. So here we have five. If I shift five left, so I'm going to shift this left by one. Right. So I'm going to take this five right here, right here, five. I'm going to shift this down by one. Okay. So when I shift it down by one, what do I get? So here this, this bit originally, right? This one originally was on the right side far right. Now it's going to move down by one. So it's going to now go here, right? And this zero is going to be here and this one is going to be here. So now we're going to have, so we're going to have one, right? One, then we're going to have zero and one, right? One, zero, one, right? So all, we, everything here got shifted to the left, to the left by one. Okay. And because I want to get shifted to the left by one, right? We append a zero at the end. Okay. So all the previous bits here, a one, zero, one, zero got shifted left by one, and then we just added a zero to the end, right? So like this, this one became the year, zero became here, became here, and then this is what happens in base two. This is what you get. Okay. When you shift it down by one. So now what happens? What, what is the answer for this now? Well, let's convert this back into the number form. So in this case, we have zero, one, zero, one, right? So, so let's convert this back into base 10. So here we have two to the zero to the one to the two, two to three. So here, so two to the three, right? So we have two to the third, two to the second, two to the first, two to the zero, right? And then we just put ones in front of these, right? This is how you convert and then this is a zero. Okay. And then you just add them up. This is how you convert binary back into the thing. So now here we have four times two, two to the third is eight. I had four times use eight. This is zero. I know two to the first is two. And then two to the zero, zero is one, zero, so zero. So right, so eight plus two, then this equals to 10. So what happens when you shift left by one, you end up multiplying the previous answer, the previous answer that we had by two, right? So every time you shift something left by one, you multiply the previous answer by two. Okay. So like if I shifted this five left by one, one bit, this is going to equal to 10. In base 10. Okay. So that's what this does. Okay. So yeah. Now let's see what happens now. How do you shift something down by, let's say I want to shift something down by two bits instead. So now let's see five is a base 10, right? Now I'm going to shift it down by two bits, two bits. Okay. So before we shift it down by one bit, now we're going to shift it down by two bits. So now here we have originally was five was this, right? This was five, right? It's five and base two is this, right? So to shift it down, what we're going to do is we're going to originally we're going to move the bit down by one and then move it down by one again. So now we're going to have, so we have one, zero, one, right? So we moved it down one. So normally you would add a zero if you move it down one, but now we're going to add two zeros because we moved down twice. Okay. So that's what happened, right? We add two zeros because we move it down by twice. We move this down one and then move down one here. This moved down by one and then down one. This down one by down one. This down one down one. Okay. So that's what we get. And yeah, you just appended two zeros at the end. So now if you convert this back into decimal form, what do you get? So do we now let's just label all the powers of twos, two to zero, two to one, two to two, two to three, two to four, two to four. So two to the four plus let's see. Two to the fourth, right? Two to the third, two to the second plus one times two to the second. Okay. And this gets you two to the fourth power is 16, right? Two to the fourth power 16 and then two to the second is four. So we plus four and then we get 20. Okay. So this 20 represents in base 10. Okay. So what happens when you shift it down by two, right? So what we what happened was is that we multiplied five times two to the second power. That's what that's what happened. Okay. So we did five. So this is actually equal to so this is equal to five times two to the second power. Okay. So anytime you shift shift something down by and you multiply it to the certain power to its power, right? So for this is equal to five times two five times four, which is gets you 20. So that's what this is. That's the same answer that we got here. Okay. So anything if you shift something down by and so let's say I've shift five base 10 down by and right. This is actually equivalent to five times two to the end. Okay. That's what it means. Right. That's what this is doing. Okay. So okie dokie that is basically shifting left right shifting left now what happens when I shift right so shifting right is basically the same thing. Okay. So let's say I have five to the five base 10 right. So this is equivalent to one zero one do right and instead I'm going to shift this to the right right. We're going to shift it right by one. So happens if you shift everything to the right. Okay. So basically when you shift everything to the right all the values of all the bits here gets moved down by one. So this zero moves down by one. This moves down and this moves down. So what we're going to get here is we're going to get equivalent of when you shift this down by one. This goes away but the zero becomes zero and you have one and we have zero. So this is going to become zero one zero and this last bit goes away. So this is going to be here and then this is now we add a pen to zero to in front of it just in case we have four bits right because you could depend upon as many zeros in front of your bits. That's what you could do. Okay. So then if you convert this and back into the decimal form we have a two to zero to the one. So now we have one times two to the one plus two to the zero zero times two to zero which is zero. The this gives you two. Okay. So whenever you shift down something right by one or shift it right this five is you're actually dividing it by two right so if I take this shift it down by n right let's say I shift it down to the right by n what you're doing is you're basically doing five divided by two to the end. That's what you're doing. So here what we did was we did five divided by two to the first right and this actually got us to two because when five divided by two to the first would give you it basically gives you two and then it cuts off the last decimal values so it rounds it down so that's what it does that's what that's what programming does so that gives you actually two right so it cuts it down so that's basically the equivalent of bit shifting to the left and shifting to the right this is a pretty fast video you just so when you shift right you're actually dividing by to the end shift left you actually just multiply by two dn okay so yeah that's basically how you do this video where you come to subscribe I'll check you guys later.