 Yeah, hello all So this video is meant to be an explanatory helper for some of the code that we covered in Golan session 2 I created this because a number of people Seem to struggle a little bit with the binary code and I figured that having this video out there would be just a good idea to also help explain the Example code that sits at the github repo Which you should be seeing as part of this video and is also in the comments so to Get right into it. We're gonna look at a Couple of the binary operators and we're gonna look at bit testing as well and hopefully By the time this video is done I'll have left people with a clearer picture of how all of this works from a more Theoretical perspective rather than simply a code perspective So to jump right in The first thing that we are going to take a look at is the bitwise and operator Basically, if you take two numbers and you and them together The binary that is in those two numbers Will produce the results such that if you're ending a bit that is unset or zero With a bit that is Unset again zero you will get a result of zero if you are ending a bit that is set being one Versus a bit that is unset you will end up with zero again and only if both bits That you are ending together or set will you end up with one so one and one And it together is one zero and one and it together is zero zero and zero and it together is zero as per The following we can see it here quite clearly Where you can see The zeros and it together or zero one and to zero zero One and it to one is one. So that's the bitwise and operator moving on to the bitwise or operator Again, we're looking at this from a bit to bit perspective and with an or If either of the bits is set to one you will get a result of one if If both the bits are zero you'll end up with zero But as I said if either of the bits are one with an or you get one as per the following You can see in this case because we have a Set bit being one in Every single column here other than this first column what we end up with is a Lot of ones and only that first column is zero The next slide that we're going to be moving on to is our exclusive or operator and An exclusive or otherwise known as a door sometimes The result will be one if the input and modifier bits are not equal Otherwise the result is zero So what this means is zero and zero on an exclusive or is going to be zero One and one on an exclusive or will be zero However, if the bits are zero and one or one and zero you will end up with a result of one and this can be seen over here Where we see that zero and zero is zero one and zero is one One and one is zero, etc. Etc. Etc. Etc. So that's your exclusive or operator then we're going to talk a little bit now about shifting bits and What happens when you take a number that is made up of a certain number of bits and you shift it To the right or to the left So in this first representation, we're going to take this row of Binary bits all set at the moment to one and we're going to shift them Going one place to the right First thing that happens is that bit in bit seven gets dropped it gets thrown away Then everything from bits zero through six moves to the right such that the original bit zero Now sits in position one and the original bit six now sits in position seven and where The original start of this was at bit zero is now simply a zero it gets padded on that side of it So that you still end up with an eight bit number Effectively all that is happening here is all those bits are moving off to the right the most right bit gets dropped The most left bit ends up as a zero What this effectively does when you do that is actually have the number in question It acts almost as if you were dividing the number by two Obviously We're not dealing with floats here in this particular example so If you divide an odd number here, it's going to end up rounding down I believe Then we are going to talk about shifting left shifting left Effectively does exactly the same thing Where we are going to move bits one through seven To equate to bits zero Through six, but zero gets dropped as per the following And in this case the most right hand bit gets padded with zero again and we end up With what is there on the screen The next thing to look at Is testing these bits Now a lot of people seem to have issues with this when I was teaching it in the code So let's talk a little bit about this effectively all we are going to be doing here is doing a shift And then an ant So the first thing that we're going to do is take this number Which is currently set as all ones and we're going to say we want to be testing bit four That means that we have to shift this By three bits going to the right So we are shifting off bits seven six and five So that bit four becomes our right hand most bits And bits zero one and two will end up as zero as we pad On the left hand side That can be illustrated As per what you see there on the screen Once we end up with that Remember we're testing bit four and bit four is now in position number seven If we take this number and we do a and on it And we end it with the number one which is The binary equivalent of zero zero zero zero zero zero zero one One is just a single bit that is set As per what's on your screen When we perform that ant because remember an ant takes a zero And a zero and makes it a zero a one and a zero will also end up as zero because only when both bits are set In an and do you end up with one? We will end up with the binary equivalent of one And very simply put when you do this what you will end up with is saying that if Your results On a query like this after the shift and after the and Is one That means that the bit you were testing was set If it's zero the bit that you were testing would not be set Because you would end up if that bit was zero in position seven which was originally position four that you're testing Zero and one when added together would be zero So that's effectively it you're shifting Removing all the other bits back to zero other than the bit that you're testing Then test that against one with an and You end up with one bit was set if you end up with zero it wasn't And really hope that helps you guys And you can post comments or questions in the chat And hopefully We have lots of success with people understanding those videos as we move on to the next session Which um, I'm quite looking forward to Go lang session three Is going to be focusing on functions and all their different types Um, I hope to see all of you guys there. Thanks so much