<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bit manipulation Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/bit-manipulation/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/bit-manipulation/</link>
	<description></description>
	<lastBuildDate>Mon, 29 Dec 2025 08:55:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>bit manipulation Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/bit-manipulation/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &#038; Rotates Tutorial</title>
		<link>https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/</link>
					<comments>https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 29 Dec 2025 08:55:41 +0000</pubDate>
				<category><![CDATA[Assembly Language]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[AND OR XOR]]></category>
		<category><![CDATA[arithmetic shift]]></category>
		<category><![CDATA[assembly language tutorial]]></category>
		<category><![CDATA[assembly programming]]></category>
		<category><![CDATA[bit manipulation]]></category>
		<category><![CDATA[bit rotation]]></category>
		<category><![CDATA[bit shifting]]></category>
		<category><![CDATA[bitwise operations]]></category>
		<category><![CDATA[computer architecture]]></category>
		<category><![CDATA[gdb debugging]]></category>
		<category><![CDATA[logical shift]]></category>
		<category><![CDATA[low-level programming]]></category>
		<category><![CDATA[two's complement]]></category>
		<category><![CDATA[x86-64 assembly]]></category>
		<category><![CDATA[Yasm assembly]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=272</guid>

					<description><![CDATA[<p>Learn bitwise operations in x86-64 assembly language including AND, OR, XOR, NOT, logical and arithmetic shifts, and bit rotations with practical examples and GDB debugging.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/">x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial" width="1380" height="776" src="https://www.youtube.com/embed/N8Nciq6l5IU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">In this hands-on tutorial, we dive into bit manipulation in x86-64 assembly using Yasm on Ubuntu. We cover the basics of logical operations like AND, OR, XOR, and NOT, then move into shifting (logical vs arithmetic), rotating bits, and why signed vs unsigned matters for shifts.</p>



<p class="wp-block-paragraph">I explain each concept on paper first, then show real code examples running in GDB to prove how the bits change. We look at patterns in registers, see what happens with negative numbers in two&#8217;s complement, and even touch on how shifts can multiply or divide by powers of 2.</p>



<p class="wp-block-paragraph">Perfect if you&#8217;re learning low-level programming, reverse engineering, or just curious about how bits work under the hood. No prior assembly knowledge needed, but it&#8217;ll help if you&#8217;ve seen my other videos.</p>



<p class="wp-block-paragraph">Like and subscribe for more assembly tutorials!</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody.</p>



<p class="wp-block-paragraph">In this video, we&#8217;re going to talk all about manipulating bits in x86-64 Yasm assembly within</p>



<p class="wp-block-paragraph">Ubuntu.</p>



<p class="wp-block-paragraph">But if you&#8217;re not using Yasm or you&#8217;re not on Ubuntu, this video is probably going to</p>



<p class="wp-block-paragraph">be pretty useful to you anyway, because I&#8217;m going to talk about the basic concept of manipulating</p>



<p class="wp-block-paragraph">bits in various ways.</p>



<p class="wp-block-paragraph">We&#8217;re going to talk about some basic logical operators like ANDing, ORing, XORing, and</p>



<p class="wp-block-paragraph">XORing, and then we&#8217;re going to talk about shifting the bits to the left and the right,</p>



<p class="wp-block-paragraph">and then we&#8217;re going to talk about the difference between shifting without any respect for whether</p>



<p class="wp-block-paragraph">the number inside of the bits is an actual integer, or whether we just consider them</p>



<p class="wp-block-paragraph">to just be bits by themselves, or whether we&#8217;re actually respecting the bits as numbers,</p>



<p class="wp-block-paragraph">and also we&#8217;re going to look at the rotation instruction.</p>



<p class="wp-block-paragraph">So first I&#8217;m going to explain this, I&#8217;m going to write it down in a pad, and then I&#8217;m going</p>



<p class="wp-block-paragraph">show you a program that actually does it just so we can prove that it all works.</p>



<p class="wp-block-paragraph">Okay, so for starters, let me open up a little notepad here.</p>



<p class="wp-block-paragraph">What the heck am I even talking about? Let me write this down because I forgot this on my</p>



<p class="wp-block-paragraph">first take I spent like five minutes, blew right past the explanation of and and or and xor because</p>



<p class="wp-block-paragraph">I forgot that that was supposed to be part of this video. We&#8217;re going to look at and or and xor</p>



<p class="wp-block-paragraph">at least for now and then we&#8217;re going to look at shifting and then we&#8217;re going to look at rotating.</p>



<p class="wp-block-paragraph">at rotating. Okay so first off what is anding? I&#8217;ve explained that in another video but long</p>



<p class="wp-block-paragraph">story short and just requires that two bits that you&#8217;re comparing against each other are both a one</p>



<p class="wp-block-paragraph">in order to receive a one and so any other pair like a zero versus a one or one versus a zero or</p>



<p class="wp-block-paragraph">two zeros are just going to be a zero. So and means both bits that you&#8217;re comparing have to be a one</p>



<p class="wp-block-paragraph">The OR is pretty easy.</p>



<p class="wp-block-paragraph">If either of the bits is a 1, then the result is going to be 1.</p>



<p class="wp-block-paragraph">So if I say 1 versus 1, the result is going to be 1.</p>



<p class="wp-block-paragraph">If I say 0 versus 1, the result is going to be a 1.</p>



<p class="wp-block-paragraph">Or if I say 1 versus 0, the result is going to be a 1.</p>



<p class="wp-block-paragraph">In the only case where you end up with a 0, it&#8217;s just going to be 0 versus 0 results in a 0.</p>



<p class="wp-block-paragraph">To upgrade to exclusive OR, basically exactly 1 bit needs to be a 1.</p>



<p class="wp-block-paragraph">bit needs to be a one and if two or zero are a one then the result is a zero which means here when</p>



<p class="wp-block-paragraph">we have the two ones at the top the answer is going to be a zero these are the two stay the</p>



<p class="wp-block-paragraph">same and this one stays the same so that&#8217;s xor again i have another video where i explain this</p>



<p class="wp-block-paragraph">a little bit better but i&#8217;m just doing like a quick overview shifting is pretty interesting</p>



<p class="wp-block-paragraph">because let me do a pattern let&#8217;s say zero one one zero suppose we just have four bits</p>



<p class="wp-block-paragraph">to the left or to the right. So imagine left, if I shift them to the left, then what I&#8217;m really</p>



<p class="wp-block-paragraph">doing is I&#8217;m just taking off that zero on the end and padding on the right with a zero. And then if</p>



<p class="wp-block-paragraph">I&#8217;m shifting to the right, then well, it&#8217;s to the right. I&#8217;m just going to, you know, take off,</p>



<p class="wp-block-paragraph">let&#8217;s see the zero on the right side and pad with the zero on the left. Be careful though, because</p>



<p class="wp-block-paragraph">or logical shifting. I haven&#8217;t actually shifted with respect to the original number. Think</p>



<p class="wp-block-paragraph">about this. That number right there on line three, if we just consider that an unsigned</p>



<p class="wp-block-paragraph">integer or just bits, then what I just did with the shifting is fine. But what if that</p>



<p class="wp-block-paragraph">was a two&#8217;s complement number that can represent a signed integer? If it&#8217;s two&#8217;s complement</p>



<p class="wp-block-paragraph">or if it&#8217;s just like a signed integer, then the leftmost bit being a zero tells me that</p>



<p class="wp-block-paragraph">result of my left shift, there&#8217;s a one now in that first position, which tells me that&#8217;s</p>



<p class="wp-block-paragraph">probably a negative number.</p>



<p class="wp-block-paragraph">We could face a similar problem with shifting to the right.</p>



<p class="wp-block-paragraph">I mean, we didn&#8217;t this time.</p>



<p class="wp-block-paragraph">It just looks like it actually shifted and the answer is going to end up being right.</p>



<p class="wp-block-paragraph">But what if we shifted something else right?</p>



<p class="wp-block-paragraph">Let&#8217;s see, what am I going to do here?</p>



<p class="wp-block-paragraph">One, one, zero, zero.</p>



<p class="wp-block-paragraph">What if I shifted that number one to the right?</p>



<p class="wp-block-paragraph">The answer would be zero, you know, one, one, zero, right?</p>



<p class="wp-block-paragraph">you know 110 right but then that&#8217;s wrong because the original number was negative because there&#8217;s</p>



<p class="wp-block-paragraph">a one in the first position but the result is a zero so if i&#8217;m not careful about what instructions</p>



<p class="wp-block-paragraph">i&#8217;m using and how to respect whether the number i&#8217;m shifting is actually considered an integer</p>



<p class="wp-block-paragraph">assigned integer or if it&#8217;s just bits if i don&#8217;t respect that then i could end up ruining the</p>



<p class="wp-block-paragraph">number so keep that in mind we&#8217;re going to do several examples of that i&#8217;m not going to show</p>



<p class="wp-block-paragraph">shift by hand I&#8217;m just going to show you what the instructions in the assembler</p>



<p class="wp-block-paragraph">will do so then the other thing that we should talk about is rotating so imagine</p>



<p class="wp-block-paragraph">that I rotate this number one to the right well nothing really happens</p>



<p class="wp-block-paragraph">visually but what you&#8217;re supposed to do if we rotate to the right you take the</p>



<p class="wp-block-paragraph">number on the very right side and you just pop it onto the front so it sort of</p>



<p class="wp-block-paragraph">it doesn&#8217;t fall off and get replaced by a zero or get replaced by a one depending</p>



<p class="wp-block-paragraph">moves to the other side so if I shift this again maybe let&#8217;s shift it one more</p>



<p class="wp-block-paragraph">time to the right I&#8217;m gonna take that one and pop it off the right side and</p>



<p class="wp-block-paragraph">put it on the very front so see do you see how there it&#8217;s kind of rotating I do</p>



<p class="wp-block-paragraph">this one more time actually let me copy paste this I&#8217;ll take that number on the</p>



<p class="wp-block-paragraph">right side pop it off put it back on the front then if I do it again take that</p>



<p class="wp-block-paragraph">zero pop it off put it back on the front notice how it eventually gets back to</p>



<p class="wp-block-paragraph">the original pattern and I would have to rotate you know exactly four times to</p>



<p class="wp-block-paragraph">to get that to happen same same thing applies for rotating to the left i&#8217;m not going to show you</p>



<p class="wp-block-paragraph">because uh it&#8217;s it&#8217;s the same thing as rotating to the right just in a different direction</p>



<p class="wp-block-paragraph">one thing that i forgot to say a moment ago when i was talking about shifting is uh think about this</p>



<p class="wp-block-paragraph">if we shift to the right pretend that uh we don&#8217;t really care that much let&#8217;s let me put some extra</p>



<p class="wp-block-paragraph">zeros here so that we don&#8217;t have to carry too much we don&#8217;t have to care too much about what&#8217;s</p>



<p class="wp-block-paragraph">happening with positive or negative. If you know how to convert to binary, which I&#8217;ve explained in</p>



<p class="wp-block-paragraph">other videos, then you&#8217;ll know this number is, let&#8217;s see, there&#8217;s a one and a two, and then these</p>



<p class="wp-block-paragraph">positions are four and eight. So this should be a 12, right? If I shift this to the right,</p>



<p class="wp-block-paragraph">I should be dividing this by two because the base of binary is two. So every time you kind of like</p>



<p class="wp-block-paragraph">move to the left in terms of what digit you&#8217;re looking at, you&#8217;re increasing the power of that</p>



<p class="wp-block-paragraph">every time you move to the right you&#8217;re decreasing the power of the digit by two</p>



<p class="wp-block-paragraph">so that means if I shift the entire thing to the right I should be dividing the whole thing by two</p>



<p class="wp-block-paragraph">right not just one bit so if I just take a zero off of there and put it on there I&#8217;ve now shifted</p>



<p class="wp-block-paragraph">all the bits shifted all the bits one to the right I should end up with the six let&#8217;s just</p>



<p class="wp-block-paragraph">compute what it is there&#8217;s a one there and there&#8217;s a two there and there&#8217;s a four there what&#8217;s four</p>



<p class="wp-block-paragraph">plus two that&#8217;s six so this is actually six in binary or the original number divided by two</p>



<p class="wp-block-paragraph">because we shifted to the right on the other hand if I take this number one more time and</p>



<p class="wp-block-paragraph">just kind of shift it to the left I should multiply it by two so that means I should</p>



<p class="wp-block-paragraph">expect to see a 24 let me just remove one of those zeros and put it on the right side there</p>



<p class="wp-block-paragraph">this is not a rotation I&#8217;m just kind of like filling in zeros I&#8217;m keeping it simple with</p>



<p class="wp-block-paragraph">the shifted number this is a 1, a 2, and a 4 again if you don&#8217;t know how to convert</p>



<p class="wp-block-paragraph">from binary to decimal or back see my other videos so then we basically have</p>



<p class="wp-block-paragraph">an 8 here and a 16 what&#8217;s 8 plus 16 that&#8217;s 24 24 is twice of 12 so we have</p>



<p class="wp-block-paragraph">multiplied by 2 so you could multiply by 4 by shifting twice multiply by 8 by</p>



<p class="wp-block-paragraph">shifting 3 times you know whatever you want to do but shifting is is like a</p>



<p class="wp-block-paragraph">is like a shortcut besides just to move the bits it&#8217;s also a shortcut to multiply and divide by two</p>



<p class="wp-block-paragraph">okay so that&#8217;s the basic idea let me start working on a little program here for you before I continue</p>



<p class="wp-block-paragraph">I just want you to know that my program it&#8217;s got stuff in it already we&#8217;ve got a make file here</p>



<p class="wp-block-paragraph">if I uh I edit the make file I just have a make file set up to build the program so again this</p>



<p class="wp-block-paragraph">is specific to just you know bits we&#8217;re not going to talk about make files see my other videos if</p>



<p class="wp-block-paragraph">you want to know how to make your own make file same thing for this gdb.txt file I&#8217;ve just put</p>



<p class="wp-block-paragraph">commands that I&#8217;m going to send to gdb my debugger of choice this is not a gdb video I haven&#8217;t</p>



<p class="wp-block-paragraph">actually made my gdb video yet so look out for that in this in the somewhat near future</p>



<p class="wp-block-paragraph">so we&#8217;re just going to focus on the actual program for now anyway so I&#8217;ve got a solution</p>



<p class="wp-block-paragraph">Anyway, so I&#8217;ve got a solution already set up here.</p>



<p class="wp-block-paragraph">Let me start copy pasting some stuff in there.</p>



<p class="wp-block-paragraph">Going to copy paste my data section.</p>



<p class="wp-block-paragraph">So first off,</p>



<p class="wp-block-paragraph">my sample program is just gonna have codes for writing,</p>



<p class="wp-block-paragraph">you know, with the system call</p>



<p class="wp-block-paragraph">and exiting with the system call.</p>



<p class="wp-block-paragraph">And then I&#8217;m gonna output to standard output</p>



<p class="wp-block-paragraph">and I&#8217;m gonna do a zero return code.</p>



<p class="wp-block-paragraph">If you don&#8217;t know that,</p>



<p class="wp-block-paragraph">see my other videos that I&#8217;ve already put out.</p>



<p class="wp-block-paragraph">I&#8217;m gonna make a sample string where I just say,</p>



<p class="wp-block-paragraph">I just say hello my name is Gibson Montgomery Gibson that&#8217;s not my name but I love those names</p>



<p class="wp-block-paragraph">I&#8217;m just going to say hello basically when the program starts then I have some bit strings here</p>



<p class="wp-block-paragraph">that will help me with the you know help me demonstrate some of the bitwise operations</p>



<p class="wp-block-paragraph">the ending and the oring and the shifting and whatever and then I&#8217;m going to put a negative</p>



<p class="wp-block-paragraph">number here as a variable just to prove to you that sometimes the bitwise or logical shifting</p>



<p class="wp-block-paragraph">break a number if the number is supposed to actually be assigned integer and and use that</p>



<p class="wp-block-paragraph">as evidence for why you should use arithmetic shifting so now I&#8217;m going to start my program</p>



<p class="wp-block-paragraph">here let&#8217;s see my entry point should start at line 30 I got to be super careful about this</p>



<p class="wp-block-paragraph">because if I don&#8217;t know 26 if I don&#8217;t then all of my debug statements are going to have to be</p>



<p class="wp-block-paragraph">it lined up correctly so i&#8217;m basically just going to print the hello message and then maybe you know</p>



<p class="wp-block-paragraph">what at the very end i&#8217;m going to exit from the system with a system call so basically if we run</p>



<p class="wp-block-paragraph">this program again system calls and everything like that are not part of this video see my other</p>



<p class="wp-block-paragraph">videos but uh if this works we should see just like a simple message okay so that&#8217;s it my name</p>



<p class="wp-block-paragraph">Conmary Gibson. Okay.</p>



<p class="wp-block-paragraph">So then the next thing that I&#8217;m going to do is I&#8217;m going to show you a bitwise</p>



<p class="wp-block-paragraph">and operation. So I&#8217;m going to copy paste that should start on line 42.</p>



<p class="wp-block-paragraph">And if I get this wrong, the debugging is going to be awful.</p>



<p class="wp-block-paragraph">I was trying to make this a pure assembly program without a bunch of extra work.</p>



<p class="wp-block-paragraph">I guess I could have linked GCC so I could just print results to the terminal,</p>



<p class="wp-block-paragraph">but whatever too late now. So it starts on 42.</p>



<p class="wp-block-paragraph">and ends on 51 okay so I think that&#8217;s good so the instruction for ending doing</p>



<p class="wp-block-paragraph">a logical and between two registers which are full of bits and then what</p>



<p class="wp-block-paragraph">will happen is every bit gets anded against its own course or I guess the</p>



<p class="wp-block-paragraph">corresponding bit in the other other register is just and so what I&#8217;m doing</p>



<p class="wp-block-paragraph">first is I&#8217;m gonna set up the registers so I&#8217;m gonna move the a sequence which</p>



<p class="wp-block-paragraph">sequence, which if you look up is just, you know, I put a bunch of bits. So like in hex,</p>



<p class="wp-block-paragraph">I like to type hex more than binary when I&#8217;m just kind of putting stuff in there.</p>



<p class="wp-block-paragraph">So, you know, each F is basically four ones. So it&#8217;s going to be like, I guess, 16 ones,</p>



<p class="wp-block-paragraph">and then a bunch of zeros, and then, you know, a few ones, and then some zeros and ones.</p>



<p class="wp-block-paragraph">So I&#8217;m just making a little pattern for bits A. Don&#8217;t think that they mean anything right now.</p>



<p class="wp-block-paragraph">And I&#8217;m going to make a different pattern with bits B. And when we look into the debugger,</p>



<p class="wp-block-paragraph">And when we look into the debugger, we should see the before and after patterns so we can kind of see what the AND instruction did.</p>



<p class="wp-block-paragraph">So I&#8217;m going to move bits A and bits B into R10 and R11.</p>



<p class="wp-block-paragraph">Then I&#8217;m going to move, so these are going to be like the original bits that we can inspect later.</p>



<p class="wp-block-paragraph">this AND instruction against R11 which is the B pattern. So I&#8217;m basically taking the A pattern</p>



<p class="wp-block-paragraph">and I&#8217;m ANDing it against the B pattern but I&#8217;m also loading up the registers so we can see</p>



<p class="wp-block-paragraph">the A pattern then the B pattern and then the result of ANDing them together.</p>



<p class="wp-block-paragraph">Finally on line 50 here I&#8217;m using a NOPE which is just a non-operation so that I can easily</p>



<p class="wp-block-paragraph">break the debugger so we can sort of inspect the program and see what&#8217;s going on inside of there.</p>



<p class="wp-block-paragraph">program and see what&#8217;s going on inside of there. You know what, let me, uh, let me open this up</p>



<p class="wp-block-paragraph">again here so that I can control where I&#8217;m breaking. So 48 is where the nope is. That&#8217;s</p>



<p class="wp-block-paragraph">totally wrong. I&#8217;ve already ruined my program somehow. It&#8217;s going to be 50, I guess. All right,</p>



<ol start="50" class="wp-block-list">
<li>And what I&#8217;m doing inside of this, and again, this is not a GDB video. I&#8217;m just saying,</li>
</ol>



<p class="wp-block-paragraph">let&#8217;s break at line 50 so I can kind of poke around. And I&#8217;m going to comment all these</p>



<p class="wp-block-paragraph">And I&#8217;m going to comment all these things out for now.</p>



<p class="wp-block-paragraph">That&#8217;s going to happen at the very end.</p>



<p class="wp-block-paragraph">It&#8217;s going to be majestic.</p>



<p class="wp-block-paragraph">How many different things we can look at.</p>



<p class="wp-block-paragraph">So I&#8217;m telling GDB not to execute any of these instructions, except for the, uh,</p>



<p class="wp-block-paragraph">the break point instructions.</p>



<p class="wp-block-paragraph">So we can just break on line 50.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Hopefully this works.</p>



<p class="wp-block-paragraph">I&#8217;m going to now use make debug, which under the hood is just going to be compiling and</p>



<p class="wp-block-paragraph">then telling GDB to launch with the name of my program inside of it.</p>



<p class="wp-block-paragraph">And then to execute those things.</p>



<p class="wp-block-paragraph">and then to execute those things.</p>



<p class="wp-block-paragraph">So it hits breakpoint number 50.</p>



<p class="wp-block-paragraph">There&#8217;s a bunch of crap that gets printed.</p>



<p class="wp-block-paragraph">And I can now inspect my registers.</p>



<p class="wp-block-paragraph">I&#8217;m going to go info R for just info registers.</p>



<p class="wp-block-paragraph">And let&#8217;s see.</p>



<p class="wp-block-paragraph">So we had R10, 11, and 12.</p>



<p class="wp-block-paragraph">So if we look at the terminal, you can see that R10, the hex version,</p>



<p class="wp-block-paragraph">has the original pattern of the A sequence,</p>



<p class="wp-block-paragraph">and then R11 has the original pattern of the B sequence.</p>



<p class="wp-block-paragraph">original pattern of the b sequence if we do a logical and and put the result into r12 then</p>



<p class="wp-block-paragraph">you should see let me just double check that that&#8217;s definitely r12 yeah then you should see</p>



<p class="wp-block-paragraph">the result of ending all of the f&#8217;s together remember that an f is just four ones so i&#8217;m kind</p>



<p class="wp-block-paragraph">of simplifying it a little bit you could make yours more complicated with lots of randomness</p>



<p class="wp-block-paragraph">in your ones and zeros just to prove it to yourself but notice how r12 only has an f</p>



<p class="wp-block-paragraph">So like FF means F, F0 means 0, F0 means 0, you know, and so forth.</p>



<p class="wp-block-paragraph">0F means 0.</p>



<p class="wp-block-paragraph">So only where you see two Fs will you see an F in the final target pattern.</p>



<p class="wp-block-paragraph">So that&#8217;s a logical AND, and that&#8217;s how you do it in Yasm Assembly.</p>



<p class="wp-block-paragraph">You just load up a register with some bits, R12.</p>



<p class="wp-block-paragraph">We loaded them up with the first pattern.</p>



<p class="wp-block-paragraph">And then we take the second pattern and say that&#8217;s what I want to AND it against.</p>



<p class="wp-block-paragraph">that&#8217;s what I want to end it against. And you can have that in a register or I think an immediate</p>



<p class="wp-block-paragraph">or a memory location. So we&#8217;re just ending these registers together. And you know that they&#8217;re</p>



<p class="wp-block-paragraph">loaded up with patterns A and B. So nothing too hard at this point. Let&#8217;s do a, let&#8217;s look at</p>



<p class="wp-block-paragraph">bitwise or this should start on line 52 or I&#8217;m screwing myself. 52. Okay. 52. So same thing,</p>



<p class="wp-block-paragraph">up R10 and R11 with the bit patterns and then we&#8217;re going to move the first bit pattern</p>



<p class="wp-block-paragraph">into R12 so that we can or it against the second pattern and so basically R10 and 11</p>



<p class="wp-block-paragraph">will have the original bit patterns R12 will have the result of oring them.</p>



<p class="wp-block-paragraph">Then we&#8217;ll do a nope on line 60 so I want to break here on line 60.</p>



<p class="wp-block-paragraph">Yep I ruined all my line numbers. What did I do wrong? I think I just have it offset by 2 now</p>



<p class="wp-block-paragraph">two now for some reason so if we just kind of run the program now in the debugger again i&#8217;m going to</p>



<p class="wp-block-paragraph">quit and then yes if we clear and make debug probably clear was unnecessary we&#8217;re broken at</p>



<p class="wp-block-paragraph">line 60 if i say info registers the registers in question are oh shoot um 10 11 and 12 right so</p>



<p class="wp-block-paragraph">we look at 10 and 11 they have the same pattern as before and 12 has a lot more f&#8217;s because if</p>



<p class="wp-block-paragraph">has a lot more F&#8217;s because if either of the patterns had an F,</p>



<p class="wp-block-paragraph">then the resulting pattern would have an F.</p>



<p class="wp-block-paragraph">So this is a logical OR.</p>



<p class="wp-block-paragraph">Same idea as AND in terms of the way you format the instruction and the OPS,</p>



<p class="wp-block-paragraph">but it ORs instead of ANDs.</p>



<p class="wp-block-paragraph">Okay, no problem.</p>



<p class="wp-block-paragraph">Let&#8217;s move on.</p>



<p class="wp-block-paragraph">Next thing I want to show you is the XOR, which is pretty cool.</p>



<p class="wp-block-paragraph">By the way, so far we&#8217;re just operating on bits.</p>



<p class="wp-block-paragraph">We don&#8217;t consider these bits to actually be numbers.</p>



<p class="wp-block-paragraph">maybe they are but we should probably be careful about that anyway so I&#8217;m going to say let&#8217;s check</p>



<p class="wp-block-paragraph">out our bitwise xor which is exclusive or which means exactly one bit in any pair needs to be a</p>



<p class="wp-block-paragraph">one for the resulting bit to be a one and of course per usual all bits will be checked against each</p>



<p class="wp-block-paragraph">other in the pair of of bit patterns it&#8217;ll be one bit at a time from each pattern that gets checked</p>



<p class="wp-block-paragraph">Okay, so it starts on 62 and then we got a nope there.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So same thing that we did before.</p>



<p class="wp-block-paragraph">We&#8217;re just loading up two registers with the bit patterns and then R12 is going to be the</p>



<p class="wp-block-paragraph">result of exclusive oring or X oring the two bit patterns.</p>



<p class="wp-block-paragraph">So that means we&#8217;re going to break on line 70.</p>



<p class="wp-block-paragraph">Now, let me just get rid of my other break point, change that 68 to a 70.</p>



<p class="wp-block-paragraph">And now I should quit.</p>



<p class="wp-block-paragraph">bug we&#8217;re at 70 good info registers so I think we said it was 10 and 11 had the original bit patterns</p>



<p class="wp-block-paragraph">and notice the resulting bit pattern it only has an f in a position where there was exactly</p>



<p class="wp-block-paragraph">one f between the two input patterns so</p>



<p class="wp-block-paragraph">wait did I just do something wrong here what did I just do wrong</p>



<p class="wp-block-paragraph">hang on a second I&#8217;m seeing something bad x or r12 am I looking at r12</p>



<p class="wp-block-paragraph">Yeah.</p>



<p class="wp-block-paragraph">R10 and 11.</p>



<p class="wp-block-paragraph">Did I just do something wrong?</p>



<p class="wp-block-paragraph">10 and 11 and then we load 10 up into 12 and then we XOR it by 11 and then it stores it</p>



<p class="wp-block-paragraph">in 12.</p>



<p class="wp-block-paragraph">Something&#8217;s a little fishy here.</p>



<p class="wp-block-paragraph">Exactly one.</p>



<p class="wp-block-paragraph">XOR.</p>



<p class="wp-block-paragraph">I don&#8217;t like that.</p>



<p class="wp-block-paragraph">Oh, I understand now.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So that was a little scary.</p>



<p class="wp-block-paragraph">This has shifted because the printout is not great.</p>



<p class="wp-block-paragraph">Because the printout is not great. See how there&#8217;s like a blank space here?</p>



<p class="wp-block-paragraph">That threw me off. So you have to imagine that all of the bit patterns are kind of shifted.</p>



<p class="wp-block-paragraph">Maybe I should just copy paste this.</p>



<p class="wp-block-paragraph">I was worried that I suddenly didn&#8217;t know how to do an XOR in assembly.</p>



<p class="wp-block-paragraph">So let me get rid of these integers here.</p>



<p class="wp-block-paragraph">Notice how there&#8217;s just a blank space that shifted everything and threw it off in terms of the display.</p>



<p class="wp-block-paragraph">So I&#8217;m going to do this.</p>



<p class="wp-block-paragraph">And what should really happen now is that there should be a zero here.</p>



<p class="wp-block-paragraph">A zero at the front.</p>



<p class="wp-block-paragraph">a zero at the front now everything would make more sense sometimes the display likes to just</p>



<p class="wp-block-paragraph">kind of truncate things and just assume that everything will be read correctly but it wasn&#8217;t</p>



<p class="wp-block-paragraph">so notice uh in the first position both of the uh both the input patterns are are an f so the</p>



<p class="wp-block-paragraph">output pattern will be a zero you can imagine under the hood there was a bunch of ones and</p>



<p class="wp-block-paragraph">then a bunch of ones and that resulted in a bunch of zeros uh here we&#8217;ve got like an f and a zero so</p>



<p class="wp-block-paragraph">the result is going to be an f and then f and a zero and after zero zero and an f is an f</p>



<p class="wp-block-paragraph">f um and then where you see zeros that means uh there was not exactly one uh one in each bit</p>



<p class="wp-block-paragraph">position so for the let&#8217;s say the first one that&#8217;s a bunch of zeros for both input patterns so that&#8217;s</p>



<p class="wp-block-paragraph">why there&#8217;s a zero there then for the next two each of them had all ones or just the two f&#8217;s</p>



<p class="wp-block-paragraph">uh so that&#8217;s why x or says it&#8217;s a zero and so forth right so like at the end two f&#8217;s making</p>



<p class="wp-block-paragraph">Okay, that was a little scary.</p>



<p class="wp-block-paragraph">I&#8217;m glad I figured that out quickly instead of taking a million years.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So now let&#8217;s do another example.</p>



<p class="wp-block-paragraph">We&#8217;re done with XOR.</p>



<p class="wp-block-paragraph">Now let&#8217;s look at bitwise knot.</p>



<p class="wp-block-paragraph">I forgot to explain knot.</p>



<p class="wp-block-paragraph">I&#8217;m not going to redo this video.</p>



<p class="wp-block-paragraph">But let me just say that a knot is just inverting the bit.</p>



<p class="wp-block-paragraph">So if we have a zero, it becomes a one.</p>



<p class="wp-block-paragraph">And if we have a one, it becomes a zero.</p>



<p class="wp-block-paragraph">If you knot against a register that has lots of bits or a memory location that has lots</p>



<p class="wp-block-paragraph">of bits, you can do that and just every single bit in the sequence will just be flipped from</p>



<p class="wp-block-paragraph">a zero to a one or vice versa.</p>



<p class="wp-block-paragraph">So let&#8217;s see, we just did bitwise XOR.</p>



<p class="wp-block-paragraph">Now we&#8217;re going to do a knot starting on line 72, I guess.</p>



<p class="wp-block-paragraph">And then we&#8217;re going to do another nope there.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">All right.</p>



<p class="wp-block-paragraph">So now let&#8217;s get rid of the break point at the line 70 and put it at line 78 instead.</p>



<p class="wp-block-paragraph">78.</p>



<p class="wp-block-paragraph">Oh man, this video is going to take forever.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So now let&#8217;s check out bitwise knot.</p>



<p class="wp-block-paragraph">We&#8217;re going to have R10.</p>



<p class="wp-block-paragraph">Oh, I guess I should improve this because what I&#8217;m doing is I&#8217;m moving everything into</p>



<p class="wp-block-paragraph">everything into R10 and then I&#8217;m just nodding R10 so we can&#8217;t really compare R10 against itself.</p>



<p class="wp-block-paragraph">That&#8217;s not fun. Let me instead move R10 into R11 so that I can nod R11 so that we can</p>



<p class="wp-block-paragraph">see two different registers at least. Okay, so let me just update my solution real fast.</p>



<p class="wp-block-paragraph">move r11 r10 okay so now it stops at 75 and that one stops at 75 okay cool</p>



<p class="wp-block-paragraph">now we got our breakpoint should be at line 79 not 78 now we&#8217;re ready to run it and see what the</p>



<p class="wp-block-paragraph">does clear and make debug info registers so we should have r10 r11 again the formatting is a</p>



<p class="wp-block-paragraph">so I&#8217;m just going to copy paste it up here. I&#8217;m going to do this, get rid of the numbers,</p>



<p class="wp-block-paragraph">pad on the left for the missing zeros, and then now you can see clearly that all of the</p>



<p class="wp-block-paragraph">F&#8217;s were flipped to zero. Again, that means, you know, each F had four ones inside of it,</p>



<p class="wp-block-paragraph">so all those ones were flipped to a zero, so that&#8217;s why it&#8217;s a zero. Okay, so nodding, pretty easy,</p>



<p class="wp-block-paragraph">this and show the next example which was gonna be let&#8217;s see seven let&#8217;s check out bitwise rotation</p>



<p class="wp-block-paragraph">i&#8217;m going to copy paste all the way up to that nope there should start on line 81</p>



<p class="wp-block-paragraph">i paused before i took a drink of water hopefully i reminded myself later to edit the drink of water</p>



<p class="wp-block-paragraph">out i don&#8217;t know maybe you&#8217;ll be wondering why my mustache is wet right now if i did not edit it out</p>



<p class="wp-block-paragraph">I did not edit it out.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s check out bitwise rotation.</p>



<p class="wp-block-paragraph">So I&#8217;m gonna set up R10 and 11 and 12 and 13 and 14,</p>



<p class="wp-block-paragraph">all with the A pattern.</p>



<p class="wp-block-paragraph">And then I&#8217;m gonna start rotating things.</p>



<p class="wp-block-paragraph">So first I&#8217;m gonna rotate to the left R11 and then R12.</p>



<p class="wp-block-paragraph">I&#8217;m gonna rotate by one position on R11</p>



<p class="wp-block-paragraph">and then two positions on R12.</p>



<p class="wp-block-paragraph">And then I&#8217;m going to rotate</p>



<p class="wp-block-paragraph">rotate by one position for R13 and then two positions for R14 so we should see</p>



<p class="wp-block-paragraph">some interesting patterns. The NOPE is now on line 94 so I&#8217;m gonna break there</p>



<p class="wp-block-paragraph">instead whoops so I&#8217;m gonna change that and I&#8217;m now off by three it&#8217;s getting</p>



<p class="wp-block-paragraph">precarious and then I&#8217;m gonna uncomment all of my little print statements to</p>



<p class="wp-block-paragraph">show you the value of the registers after I rotate it so we should see like</p>



<p class="wp-block-paragraph">printed in the terminal just to prove to you what&#8217;s going to happen okay so man I got to</p>



<p class="wp-block-paragraph">remember what&#8217;s happening now first thing that I did was I printed r10 to show you one type of</p>



<p class="wp-block-paragraph">rotation and then I printed r10 again to show you another type of rotation so we should see the</p>



<p class="wp-block-paragraph">original and then the two rotated values and then the original again and then the other two rotated</p>



<p class="wp-block-paragraph">values so here&#8217;s the original we&#8217;re printing it in binary with the special print command in gdb</p>



<p class="wp-block-paragraph">in GDB, which is just like P slash T and then the register. So this is the original pattern</p>



<p class="wp-block-paragraph">right here. And if you just kind of squint at it for a while, you can realize that the dollar</p>



<p class="wp-block-paragraph">sign two pattern has been, uh, shifted once to the left. Actually, let me just make sure that</p>



<p class="wp-block-paragraph">I&#8217;m doing a shift and not a rotate. I&#8217;m accidentally saying the word, uh, rotate, I think. And, uh,</p>



<p class="wp-block-paragraph">that&#8217;s, oh no, no, it is rotate. Yeah. We&#8217;re going to shift later, I guess.</p>



<p class="wp-block-paragraph">I guess. Okay, so we are definitely rotating. So we should see some wrap around. I guess I used</p>



<p class="wp-block-paragraph">bad bit patterns for the wrap around. But just imagine that, you know, in this pattern right here,</p>



<p class="wp-block-paragraph">this one, if we&#8217;re rotating to the left, this one fell off and it got placed on the right side of</p>



<p class="wp-block-paragraph">of the next pattern it&#8217;s going to be the same thing basically so but this is rotation so we</p>



<p class="wp-block-paragraph">wouldn&#8217;t be reusing the bits that fell off but anyway you can see that if I rotated to the left</p>



<p class="wp-block-paragraph">by one position that whole thing is is kind of shifted to the left I shouldn&#8217;t use the word shift</p>



<p class="wp-block-paragraph">and then for the second pattern we did a rotation by two positions so all the bits are just kind of</p>



<p class="wp-block-paragraph">moved to the left compared to the very first pattern okay so no problem then the next thing</p>



<p class="wp-block-paragraph">that we&#8217;re looking at is just you know rotating to the right and you can tell that everything is</p>



<p class="wp-block-paragraph">offset by one here and it&#8217;s offset by two here so rotating to the left by one position by two</p>



<p class="wp-block-paragraph">positions rotating to the right by one position or by two positions that&#8217;s rotation in a nutshell</p>



<p class="wp-block-paragraph">okay so then the next thing that we&#8217;re going to do we&#8217;re on 94 now</p>



<p class="wp-block-paragraph">um let&#8217;s see logical shifting nope nope nope I&#8217;m gonna grab some code that will shift both</p>



<p class="wp-block-paragraph">logically and arithmetically so we can kind of see the difference</p>



<p class="wp-block-paragraph">okay so show maybe I should change this to show some some shifting</p>



<p class="wp-block-paragraph">because uh if I just say it&#8217;s logical then yeah sure uh the shift function uh the shift</p>



<p class="wp-block-paragraph">those are logical shifts but then down here when it&#8217;s a sal and sar those are arithmetic shifts</p>



<p class="wp-block-paragraph">I don&#8217;t know maybe maybe I can do that maybe I can just</p>



<p class="wp-block-paragraph">duplicate the comment maybe to make it more more intuitive so show arithmetic shifts</p>



<p class="wp-block-paragraph">Okay, I think that looks pretty good. Let me paste that into 105 on my solution so I don&#8217;t get out of sync here.</p>



<p class="wp-block-paragraph">So what&#8217;s going to happen here? We&#8217;re basically going to load up R10 with a negative number.</p>



<p class="wp-block-paragraph">I&#8217;ve chosen the number negative 12 because I kind of feel like it at least shows you a little bit for dividing and stuff like that.</p>



<p class="wp-block-paragraph">So we&#8217;re loading up R10 with a negative number, and then R11 is going to get R10, but then we&#8217;re going to shift it left by two positions.</p>



<p class="wp-block-paragraph">positions so that should be multiplying it by four but this is well a bitwise</p>



<p class="wp-block-paragraph">shifting so it it&#8217;s not going to necessarily respect the fact that the</p>



<p class="wp-block-paragraph">number is in twos complement so this is not a good idea if you consider r tend</p>



<p class="wp-block-paragraph">to be a number because sometimes the result might be right and sometimes the</p>



<p class="wp-block-paragraph">result might be wrong here it says math won&#8217;t work in my comment but sometimes</p>



<p class="wp-block-paragraph">it will accidentally work but you still want to consider it to be non-working</p>



<p class="wp-block-paragraph">It&#8217;s only good for bit shifting.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to put R12, we&#8217;re going to give it the same value as R10 and then we&#8217;re</p>



<p class="wp-block-paragraph">just going to shift it to the right by two positions.</p>



<p class="wp-block-paragraph">This will definitely break because when you shift to the right, the sine bit is going</p>



<p class="wp-block-paragraph">to get padded with a zero rather than what the actual sine bit was originally.</p>



<p class="wp-block-paragraph">So that will almost certainly break it almost every time.</p>



<p class="wp-block-paragraph">Then we&#8217;re going to use arithmetic shifts which just respect the fact that the original</p>



<p class="wp-block-paragraph">number is two&#8217;s complement.</p>



<p class="wp-block-paragraph">two&#8217;s complement so you know like we have this negative 12 number it&#8217;s going to end up being</p>



<p class="wp-block-paragraph">bits but the uh the shl and the shr instructions are not going to respect the fact that it&#8217;s</p>



<p class="wp-block-paragraph">negative 12 they&#8217;re just going to consider them to be bits but the sal shifting to the left</p>



<p class="wp-block-paragraph">arithmetically and the sar shifting to the right arithmetically are going to respect that respect</p>



<p class="wp-block-paragraph">the fact that it&#8217;s two&#8217;s complement so let&#8217;s see we&#8217;ve got all this stuff and then we&#8217;ve got a</p>



<p class="wp-block-paragraph">We&#8217;ve got all this stuff and then we&#8217;ve got a non-operation here.</p>



<p class="wp-block-paragraph">You know, again, like per usual, when we&#8217;re shifting, when we&#8217;re rotating, when we&#8217;re</p>



<p class="wp-block-paragraph">oaring, anding, whatever, it&#8217;s just the instruction name followed by both the source and the</p>



<p class="wp-block-paragraph">destination operand.</p>



<p class="wp-block-paragraph">And then the second operand is only going to be source.</p>



<p class="wp-block-paragraph">So if we have a shifting left R11, then the result is going to be stored in R11, but it&#8217;s</p>



<p class="wp-block-paragraph">going to take as the source R11 and shift it to the left by two positions.</p>



<p class="wp-block-paragraph">to the left by two positions and so forth.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So we have all of that.</p>



<p class="wp-block-paragraph">We&#8217;re going to nope on line one of what is it?</p>



<p class="wp-block-paragraph">One, one 14.</p>



<p class="wp-block-paragraph">So that means I&#8217;m going to stop breaking on 94 and I&#8217;m going to break on one 14.</p>



<p class="wp-block-paragraph">I thought it was four lines off and now I&#8217;m only two lines off.</p>



<p class="wp-block-paragraph">I think I just did something else wrong here between my source.</p>



<p class="wp-block-paragraph">Let&#8217;s see.</p>



<p class="wp-block-paragraph">Is the nope on one 14 up there?</p>



<p class="wp-block-paragraph">Yeah, it is.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Guess I didn&#8217;t do that much wrong.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s run this, but this code up here was just going to print bit patterns</p>



<p class="wp-block-paragraph">related to our rotations.</p>



<p class="wp-block-paragraph">I don&#8217;t really want that anymore.</p>



<p class="wp-block-paragraph">So I&#8217;m going to uncomment all of these other prints that relate to our shifts.</p>



<p class="wp-block-paragraph">And this is going to be a nightmare to read and interpret, but I&#8217;m going to try.</p>



<p class="wp-block-paragraph">I really should have written a more complicated program that can just print them in the terminal</p>



<p class="wp-block-paragraph">so I don&#8217;t have to like read the debugger.</p>



<p class="wp-block-paragraph">Whatever, it&#8217;s brain exercise.</p>



<p class="wp-block-paragraph">size. And I think this actually is the end of the program. 119 is the last line. Yeah. Okay.</p>



<p class="wp-block-paragraph">So we just need to run this and see what happens. So really we&#8217;re interested in these, uh, you know,</p>



<p class="wp-block-paragraph">shifting to the left twice, shifting to the right twice bit wise, and then shifting to the left</p>



<p class="wp-block-paragraph">twice, arithmetically shifting to the right twice, arithmetically. Okay. So we&#8217;ll go back to the</p>



<p class="wp-block-paragraph">terminal here and quit. And then I&#8217;m going to do make debug. And now there&#8217;s a bunch of junk.</p>



<p class="wp-block-paragraph">here&#8217;s the original number and then we&#8217;re gonna bitwise shift left binary</p>



<p class="wp-block-paragraph">notice how it just sort of you know it shifted everything to the left and you</p>



<p class="wp-block-paragraph">know we&#8217;re not using we&#8217;re not printing hex anymore because I want you to see</p>



<p class="wp-block-paragraph">the binary and then you know like the patterns are just shifted to to the left</p>



<p class="wp-block-paragraph">like see here&#8217;s the first one if we&#8217;re looking at the right side and then here</p>



<p class="wp-block-paragraph">is the first one if we&#8217;re looking at the right side for the shifted version</p>



<p class="wp-block-paragraph">A similar deal for shift right except we lost a couple of numbers there because of the display</p>



<p class="wp-block-paragraph">so I&#8217;m going to copy paste both of these real fast.</p>



<p class="wp-block-paragraph">Per usual we lost numbers due to the display so I&#8217;m going to say notice how we have two</p>



<p class="wp-block-paragraph">numbers missing here if I added zeros on the right side that&#8217;s going to change the actual</p>



<p class="wp-block-paragraph">value so I&#8217;m going to have to add them to the left and now we can clearly see that the</p>



<p class="wp-block-paragraph">shifted four positions I think to the left wait did I do that where did I where did I even just</p>



<p class="wp-block-paragraph">copy paste from original shift left and shift right okay so shift right is what it&#8217;s supposed</p>



<p class="wp-block-paragraph">to be doing let me just double check here shift right is printing r12 and what does r12 have it</p>



<p class="wp-block-paragraph">shifting right by two. Okay.</p>



<p class="wp-block-paragraph">Oh, I&#8217;m supposed to compare it to the very first one.</p>



<p class="wp-block-paragraph">Let me just double check that I have this correct now.</p>



<p class="wp-block-paragraph">Why is it</p>



<p class="wp-block-paragraph">shifting to the right? Oh gosh, I think I just lost track of myself. Let me just,</p>



<p class="wp-block-paragraph">give me a second here. Or 14.</p>



<p class="wp-block-paragraph">I&#8217;m forgetting where I copy and paste. Okay. Bitwise shift right is</p>



<p class="wp-block-paragraph">bitwise shift right is R12, not R14. Oh gosh. Did I do it wrong? Were you cringing at home?</p>



<p class="wp-block-paragraph">Maybe this will work. And the two, that&#8217;s kind of the same thing that I did before. No, no,</p>



<p class="wp-block-paragraph">it&#8217;s different. Okay. So I had it wrong before. Now I finally have it right. So you can see that</p>



<p class="wp-block-paragraph">So you can see that the bit pattern is shifted twice to the right and then on the left two zeros show up which would have destroyed a number.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So we shift it to the right and now we&#8217;re ready to look at arithmetic shift to the left and right.</p>



<p class="wp-block-paragraph">And let&#8217;s see do we have enough bits to actually print everything?</p>



<p class="wp-block-paragraph">This one should look like it&#8217;s shifted to the right just because of the way it prints.</p>



<p class="wp-block-paragraph">So that means this one is totally lined up.</p>



<p class="wp-block-paragraph">Okay so let me grab the original pattern here.</p>



<p class="wp-block-paragraph">grab the original pattern here so this is the original pattern and then if I go shift left</p>



<p class="wp-block-paragraph">in binary I&#8217;ll just put an L here and then I&#8217;ll put shift right in binary</p>



<p class="wp-block-paragraph">there we have enough bits I think in both cases so we don&#8217;t have to pad</p>



<p class="wp-block-paragraph">so now if we look at the original pattern and then we shift left arithmetically twice</p>



<p class="wp-block-paragraph">twice notice how it does kind of look like it survived right like this one moved over to the</p>



<p class="wp-block-paragraph">left twice because the sine bits are just kind of falling off but there&#8217;s enough of them that it&#8217;s</p>



<p class="wp-block-paragraph">not going to change the sine bit thank you two&#8217;s complement but when we shift to the right</p>



<p class="wp-block-paragraph">arithmetically normally we would have padded on the left with zeros remember we had zeros there</p>



<p class="wp-block-paragraph">on the left before but now that we&#8217;re respecting the arithmetic uh the the padding is correct now</p>



<p class="wp-block-paragraph">is correct now for two&#8217;s complement so that&#8217;s why there are ones there instead of zeros</p>



<p class="wp-block-paragraph">and then if you kind of look at it it&#8217;s like well we shifted twice to the right let me get</p>



<p class="wp-block-paragraph">rid of the left because we already understand that now it seems to be that the pattern is uh</p>



<p class="wp-block-paragraph">every bit is shifted over to the right the correct number of times the zeros dropped off the side</p>



<p class="wp-block-paragraph">and um the sine bits were padded on the left so everything seems to be correct and then just to</p>



<p class="wp-block-paragraph">to kind of prove to you that what we&#8217;re seeing is real, I just have the same things printed</p>



<p class="wp-block-paragraph">all over again from scratch in decimal. So originally we had our R10 as negative 12.</p>



<p class="wp-block-paragraph">And then if we do a bitwise shift to the left, it multiplies it by four. And so we&#8217;re accidentally</p>



<p class="wp-block-paragraph">correct here. Remember, this is a bitwise shift, so it doesn&#8217;t respect two&#8217;s complement. So just,</p>



<p class="wp-block-paragraph">we happen to have a starting number that would end up looking correct after we shifted it to the left.</p>



<p class="wp-block-paragraph">And then when we do a bitwise shift to the right, again, this could be disaster because we&#8217;re not</p>



<p class="wp-block-paragraph">respecting two&#8217;s complement or the sine bit. And that&#8217;s exactly what happened. You know, definitely</p>



<p class="wp-block-paragraph">if we&#8217;re shifting to the right, that should be 12 divided by four equals three or negative three.</p>



<p class="wp-block-paragraph">But instead we get this gigantic huge number because the sine bit got killed with the zeros</p>



<p class="wp-block-paragraph">killed with the zeros that were padded on the left. And then we finally try to shift left</p>



<p class="wp-block-paragraph">arithmetically. We end up still with negative 48, which is the correct number. If we&#8217;re going to</p>



<p class="wp-block-paragraph">shift left twice, that&#8217;s multiplying 12 by 4 and that&#8217;s 48 or negative 48. And then when we shift</p>



<p class="wp-block-paragraph">to the right, that should divide it by 2 twice because we&#8217;re shifting to the right by two</p>



<p class="wp-block-paragraph">positions. So that should be 12 divided by 4, which is negative 3 or sorry, negative 12 divided</p>



<p class="wp-block-paragraph">which is negative three so everything seems to be working except for a couple of moments of</p>



<p class="wp-block-paragraph">stumbling on my part which i hope you laughed at um and i think this is the end of the program so</p>



<p class="wp-block-paragraph">now hopefully you&#8217;re an expert in uh ending oring x oring nodding shifting left and right uh bitwise</p>



<p class="wp-block-paragraph">rotating. We&#8217;ve done it all in this one video. How long did this video take? 40 minutes?</p>



<p class="wp-block-paragraph">Anyway, thank you so much for watching this video. I hope you learned a little bit of stuff</p>



<p class="wp-block-paragraph">and you had a little bit of fun. I&#8217;ll see you in the next video.</p>



<p class="wp-block-paragraph">Hey everybody, thanks for watching this video again from the bottom of my heart. I really</p>



<p class="wp-block-paragraph">appreciate it. I do hope you did learn something and have some fun. If you could do me a please,</p>



<p class="wp-block-paragraph">and follow this channel or these videos or whatever it is you do on the current social</p>



<p class="wp-block-paragraph">media website that you&#8217;re looking at right now. It would really mean the world to me and it&#8217;ll</p>



<p class="wp-block-paragraph">help make more videos and grow this community. So we&#8217;ll be able to do more videos, longer videos,</p>



<p class="wp-block-paragraph">better videos, or just I&#8217;ll be able to keep making videos in general. So please do me a kindness</p>



<p class="wp-block-paragraph">and subscribe. You know, sometimes I&#8217;m sleeping in the middle of the night and I just wake up</p>



<p class="wp-block-paragraph">because I know somebody subscribed or followed. It just wakes me up and I get filled with joy.</p>



<p class="wp-block-paragraph">just wakes me up and I get filled with joy. That&#8217;s exactly what happens every</p>



<p class="wp-block-paragraph">single time. So you could do it as a nice favor to me or you could you could</p>



<p class="wp-block-paragraph">troll me if you want to just wake me up in the middle of the night just subscribe</p>



<p class="wp-block-paragraph">and then I&#8217;ll just wake up. I promise that&#8217;s what will happen. Also if you look</p>



<p class="wp-block-paragraph">at the middle of the screen right now you should see a QR code which you can</p>



<p class="wp-block-paragraph">scan in order to go to the website which I think is also named somewhere at the</p>



<p class="wp-block-paragraph">bottom of this video and it&#8217;ll take you to my main website where you can just</p>



<p class="wp-block-paragraph">kind of like see all the videos I published and the services and tutorials</p>



<p class="wp-block-paragraph">the services and tutorials and things that I offer and all that good stuff and</p>



<p class="wp-block-paragraph">If you have a suggestion for</p>



<p class="wp-block-paragraph">Clarifications or errata or just future videos that you want to see</p>



<p class="wp-block-paragraph">Please leave a comment or if you just want to say hey, what&#8217;s up? What&#8217;s going on?</p>



<p class="wp-block-paragraph">You know, just send me a comment, whatever. I also wake up for those in the middle of the night</p>



<p class="wp-block-paragraph">I get I wake up in a cold sweat. I&#8217;m like</p>



<p class="wp-block-paragraph">It would really it really mean the world to me. I would really appreciate it. So</p>



<p class="wp-block-paragraph">Again, thank you so much for watching this video and enjoy the cool music as I fade into the darkness, which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/">x86-64 Assembly Bit Manipulation: AND, OR, XOR, NOT, Shifts &amp; Rotates Tutorial</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/x86-64-assembly-bit-manipulation-and-or-xor-not-shifts-rotates-tutorial/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</title>
		<link>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/</link>
					<comments>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Mon, 30 Jun 2025 06:15:25 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[AND operator]]></category>
		<category><![CDATA[binary logic]]></category>
		<category><![CDATA[binary operations]]></category>
		<category><![CDATA[bit manipulation]]></category>
		<category><![CDATA[bitwise operators]]></category>
		<category><![CDATA[C programming]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[coding tips]]></category>
		<category><![CDATA[computer science basics]]></category>
		<category><![CDATA[NOR operator]]></category>
		<category><![CDATA[NOT operator]]></category>
		<category><![CDATA[OR operator]]></category>
		<category><![CDATA[programming tutorial]]></category>
		<category><![CDATA[tech tutorials]]></category>
		<category><![CDATA[XOR operator]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=173</guid>

					<description><![CDATA[<p>Learn bitwise operators (OR, AND, NOT, XOR, NOR) with clear examples. Perfect for beginners mastering binary logic in programming.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/">Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners" width="1380" height="776" src="https://www.youtube.com/embed/mL_wTRllqtc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Want to understand bitwise operators? This video dives into OR, AND, NOT, XOR, and NOR with easy-to-follow examples. Learn how to use these operators for flags, masks, and more in programming. Perfect for beginners or anyone wanting to master binary logic in C or other languages. I break it down with real examples, a touch of humor, and no fluff. Subscribe for more coding tutorials, and check out my site for extra resources. Drop a comment with your questions or video ideas!</p>



<p class="wp-block-paragraph">Introduction to Logical Operators 00:00:00<br>Explanation of Bitwise OR 00:00:35<br>OR Operation Examples 00:01:01<br>Bitwise OR with Multiple Bits 00:02:12<br>Using OR for Flags 00:03:52<br>Introduction to Logical AND 00:08:06<br>AND Operation Examples 00:08:29<br>Using AND as a Mask 00:10:00<br>Checking Specific Bits with AND 00:11:17<br>Introduction to NOT Operation 00:13:36<br>Introduction to NOR Operation 00:14:38<br>Introduction to XOR Operation 00:16:37<br>XOR and Neural Networks 00:16:53<br>Conclusion and Call to Action 00:18:38</p>



<p class="wp-block-paragraph">Thanks for watching!</p>



<p class="wp-block-paragraph">Find us on other social media here:</p>



<ul class="wp-block-list">
<li>https://www.NeuralLantern.com/social</li>
</ul>



<p class="wp-block-paragraph">Please help support us!</p>



<ul class="wp-block-list">
<li>Subscribing + Sharing on Social Media</li>



<li>Leaving a comment or suggestion</li>



<li>Subscribing to our Blog</li>



<li>Watching the main &#8220;pinned&#8221; video of this channel for offers and extras</li>
</ul>



<p class="wp-block-paragraph">Hey everybody! In this video I&#8217;m going to talk about basic logical operators such as OR and AND.</p>



<p class="wp-block-paragraph">Uh so let&#8217;s let&#8217;s dive right into it. What am I talking about with the OR and AND?</p>



<p class="wp-block-paragraph">Suppose for the sake of argument that this notepad is totally dark and I wanted it to be really light</p>



<p class="wp-block-paragraph">and then I have to go into the system settings to fix it. Sorry let me change my theme.</p>



<p class="wp-block-paragraph">How about that?</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So suppose for the sake of argument, we&#8217;ve got, you know, a couple of bits.</p>



<p class="wp-block-paragraph">These are going to be a bitwise operations for the most part.</p>



<p class="wp-block-paragraph">In other languages, sometimes we will say logical operator, but actually we&#8217;re just</p>



<p class="wp-block-paragraph">talking about values rather than bits individually.</p>



<p class="wp-block-paragraph">So these are bitwise operators.</p>



<p class="wp-block-paragraph">Imagine we have like a couple of bits.</p>



<p class="wp-block-paragraph">Remember the possible values for bits are just, you know, a zero and a one binary.</p>



<p class="wp-block-paragraph">So suppose we have a couple of values.</p>



<p class="wp-block-paragraph">values, let&#8217;s say we have a zero here and a one.</p>



<p class="wp-block-paragraph">So if I apply a logical or to the zero and the one,</p>



<p class="wp-block-paragraph">the result is going to be a one because either the first bit or the second bit are a one.</p>



<p class="wp-block-paragraph">You could also expand these operators to have multiple sets of bits,</p>



<p class="wp-block-paragraph">but we&#8217;re just going to do, you know, one set against another set.</p>



<p class="wp-block-paragraph">In this case, each set is just one bit long, but we&#8217;ll do, we&#8217;ll do a more complicated stuff in a minute.</p>



<p class="wp-block-paragraph">If I have a zero and a one, then the answer there is, well, let me just put or maybe.</p>



<p class="wp-block-paragraph">The answer is a one.</p>



<p class="wp-block-paragraph">I&#8217;ll put or maybe at the top, just like or to let you know that we&#8217;re doing ors here</p>



<p class="wp-block-paragraph">on the top.</p>



<p class="wp-block-paragraph">So if we have a zero and a one, the answer is going to be a one.</p>



<p class="wp-block-paragraph">If we have a one and a zero, the answer is going to be a one.</p>



<p class="wp-block-paragraph">Also, if we have two ones, which looks like an L over there, I got to work on my penmanship.</p>



<p class="wp-block-paragraph">Then the answer is also going to be a one.</p>



<p class="wp-block-paragraph">if either of the bits in question are a one then the answer should be a one. The only case with an</p>



<p class="wp-block-paragraph">OR that results in a zero is if both of the bits are zero because neither the first or the second</p>



<p class="wp-block-paragraph">are actually a one right so this is the basic idea of using an OR operator and you can also do this</p>



<p class="wp-block-paragraph">with multiple bits at the same time like for example we could say let&#8217;s take a bunch of random</p>



<p class="wp-block-paragraph">work on the it&#8217;s the pressure dude the l&#8217;s are driving me crazy okay oh my god okay so i do that</p>



<p class="wp-block-paragraph">and i let go okay i&#8217;m just going to put some random bits uh underneath the the first set of</p>



<p class="wp-block-paragraph">random bits put like a zero here and then like a one here maybe and we&#8217;ll say that we&#8217;re going to</p>



<p class="wp-block-paragraph">do a logical or just like you might think of doing a you know addition or subtraction we&#8217;ll just say</p>



<p class="wp-block-paragraph">you know, addition or subtraction. We&#8217;ll just say we&#8217;re going to or these two sets of bits.</p>



<p class="wp-block-paragraph">Actually, these are six on the top and six on the bottom. If I add two more, then it&#8217;ll be a nice</p>



<p class="wp-block-paragraph">little bite for the top and the bottom. So I&#8217;m just going to do that, you know, to have eight</p>



<p class="wp-block-paragraph">bits on the top and eight bits on the bottom. Okay. So if I just want to logically or two sets</p>



<p class="wp-block-paragraph">of bits, literally, I just have to do one pair of bits at a time. So a one or zero is just a one.</p>



<p class="wp-block-paragraph">One or zero is just a one, a zero or one is a one, a one or zero is a one, a zero or one</p>



<p class="wp-block-paragraph">is a one.</p>



<p class="wp-block-paragraph">And then these ones, everything is just a one.</p>



<p class="wp-block-paragraph">Okay.</p>



<p class="wp-block-paragraph">So that was too easy.</p>



<p class="wp-block-paragraph">Maybe if I, I don&#8217;t know, maybe if I change one of these ones to a zero, then we would</p>



<p class="wp-block-paragraph">actually be able to have a zero somewhere in here.</p>



<p class="wp-block-paragraph">So that&#8217;s a logical or a bitwise or operator or operation.</p>



<p class="wp-block-paragraph">So you can, you can kind of use this in various ways.</p>



<p class="wp-block-paragraph">can kind of use this in various ways i mean obviously if you want to manipulate some bits</p>



<p class="wp-block-paragraph">this can be pretty useful inside of the machine but there was kind of an old school way that</p>



<p class="wp-block-paragraph">people did flags with arguments they would basically say something like this they would go</p>



<p class="wp-block-paragraph">in their computer program they would say you know flag a name it something like turn on the display</p>



<p class="wp-block-paragraph">or enable caching or just like whatever right so we&#8217;ll just have a flag we&#8217;ll call it flag a</p>



<p class="wp-block-paragraph">that value is equal to a one and then maybe flag b its value is equal to a two and then flag c</p>



<p class="wp-block-paragraph">its value would be a four and then we basically just double the value of the flag and the reason</p>



<p class="wp-block-paragraph">for that c d e f i&#8217;ll just stop with f maybe oh wait that was supposed to be 16 and that&#8217;s 32.</p>



<p class="wp-block-paragraph">the reason for that is if you double the value of each flag so that uh</p>



<p class="wp-block-paragraph">and then you can do a bitwise or against all of these flags and sort of combine multiple flags.</p>



<p class="wp-block-paragraph">Because if you think about it, if we&#8217;re talking about binary,</p>



<p class="wp-block-paragraph">if we suppose this is just a regular eight bit number, then, you know, the first bit has a</p>



<p class="wp-block-paragraph">strength of one. If you&#8217;ve seen my other videos for converting between binary and hex,</p>



<p class="wp-block-paragraph">the second bit has a strength of two. The next bit has a strength of four and then eight and</p>



<p class="wp-block-paragraph">and then 32 and 64 and then 128.</p>



<p class="wp-block-paragraph">And so if you look at the flags,</p>



<p class="wp-block-paragraph">1, 2, 4, 8, 16, 32,</p>



<p class="wp-block-paragraph">they map to only one bit.</p>



<p class="wp-block-paragraph">It&#8217;s not going to be some kind of random pattern for these numbers.</p>



<p class="wp-block-paragraph">It&#8217;s literally going to be flag A is going to look like this.</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">And then flag B is going to look like this.</p>



<p class="wp-block-paragraph">1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">five, six, seven, eight. And flag D is going to look like this. Whoops. Let me make that green.</p>



<p class="wp-block-paragraph">Still getting used to this. Oh, sorry. C is the next one. One, two, three, four, five,</p>



<p class="wp-block-paragraph">six, seven, eight. Can you see the pattern here? Let me just do D and be done with it at this</p>



<p class="wp-block-paragraph">point. One, two, three, four, five, six, seven, eight. So because we&#8217;re increasing the value of</p>



<p class="wp-block-paragraph">the flags by a power of two, or by a power of two, they&#8217;ll always correspond to just one bit.</p>



<p class="wp-block-paragraph">they&#8217;ll always correspond to just one bit, which means if you apply a logical or operation,</p>



<p class="wp-block-paragraph">you can represent a bunch of different flags with just one number.</p>



<p class="wp-block-paragraph">Think about this.</p>



<p class="wp-block-paragraph">What if I wanted to have, oh, I don&#8217;t know.</p>



<p class="wp-block-paragraph">Let me erase this.</p>



<p class="wp-block-paragraph">What if I wanted to have some, let&#8217;s say I wanted flag A and flag D and flag F just for</p>



<p class="wp-block-paragraph">the sake of argument.</p>



<p class="wp-block-paragraph">Dang, this pen.</p>



<p class="wp-block-paragraph">It&#8217;s actually my fault completely, but I need to practice.</p>



<p class="wp-block-paragraph">but I need to practice F okay and DNF so that would basically be you know 1 2 3 4 5 6 7 8</p>



<p class="wp-block-paragraph">and then D would be the 8 so a 1 0 0 0 there and then a bunch of zeros elsewhere and then the F</p>



<p class="wp-block-paragraph">So if we did an OR between all of those, then the OR is just basically 00101001.</p>



<p class="wp-block-paragraph">And if you convert that from binary to decimal, what is that?</p>



<p class="wp-block-paragraph">That&#8217;s a 1248 plus 8 plus 1248 and then a 32.</p>



<p class="wp-block-paragraph">So 41.</p>



<p class="wp-block-paragraph">just write down the number 41 and if the programmer is smart enough to you know parse all the bits</p>



<p class="wp-block-paragraph">and everything then they&#8217;ll know that you have flags a and d and f set that&#8217;s not necessarily</p>



<p class="wp-block-paragraph">something that all the modern programs do anymore it was much more popular in the olden days but i</p>



<p class="wp-block-paragraph">think some people still kind of do it especially if they&#8217;re programming in c and other languages</p>



<p class="wp-block-paragraph">where they want speed it&#8217;s pretty fast to look at bits inside of the machine so keep that in mind</p>



<p class="wp-block-paragraph">Keep that in mind now we know how to do an OR operation and we know one reason that it might be useful and</p>



<p class="wp-block-paragraph">Yeah, okay. I&#8217;m gonna move on to the next operation</p>



<p class="wp-block-paragraph">So clearing the screen now</p>



<p class="wp-block-paragraph">Hello little doggy he barked and now he&#8217;s in the room</p>



<p class="wp-block-paragraph">Let&#8217;s do</p>



<p class="wp-block-paragraph">The logical AND operation okay, so suppose we have two bits here</p>



<p class="wp-block-paragraph">in a one only if both of the input bits are a one i&#8217;m gonna whoops i accidentally cleared the whole</p>



<p class="wp-block-paragraph">entire thing let me forget where my red pen is okay and okay so if we have a zero and a zero</p>



<p class="wp-block-paragraph">the result is zero because neither of those are a one if we have a zero and a one the result is</p>



<p class="wp-block-paragraph">still going to be zero because we need both bits to be a one to result in a one so then that means</p>



<p class="wp-block-paragraph">would also result in a zero. So you get a bunch of zeros until finally you have an input pattern</p>



<p class="wp-block-paragraph">that is just two ones. And then finally the result is one. So that&#8217;s a logical and.</p>



<p class="wp-block-paragraph">Let me do a quick example so we can and a bunch of bits together. I&#8217;m just going to do more</p>



<p class="wp-block-paragraph">random bit patterns. So there&#8217;s another L there. I&#8217;m cringing. I&#8217;m self-cringing. One, two, three,</p>



<p class="wp-block-paragraph">okay so then i&#8217;ll do like another one there and like a zero there and a zero maybe a couple of</p>



<p class="wp-block-paragraph">ones maybe three ones and then a zero and then one i guess and we&#8217;ll just say that we&#8217;re going</p>



<p class="wp-block-paragraph">to end those together so and oh man i&#8217;m mixing uppercase and lowercase like crazy</p>



<p class="wp-block-paragraph">so uh to end them together you know that bit position right here that&#8217;s going to be a one</p>



<p class="wp-block-paragraph">and then we have a zero because they don&#8217;t match they&#8217;re not both one and then we have another zero</p>



<p class="wp-block-paragraph">a one and then we have a zero and a zero and a zero and a one so this is a logical and you can</p>



<p class="wp-block-paragraph">use logical ands for a wide variety of things but one thing you can kind of do somewhat easily is to</p>



<p class="wp-block-paragraph">use one number as a mask against another number for example notice how uh suppose this was the</p>



<p class="wp-block-paragraph">input number let&#8217;s just say we have the input number up top and maybe you wanted to make sure</p>



<p class="wp-block-paragraph">because you&#8217;re you&#8217;re checking for those bits individually or maybe you want to just prevent</p>



<p class="wp-block-paragraph">the input from having certain bits on for some other reason well you can you can apply the mask</p>



<p class="wp-block-paragraph">as the second bit and use a logical and i&#8217;ll say mask here sorry you can apply a mask as the second</p>



<p class="wp-block-paragraph">bit pattern and notice how in the answer there are only ones where both you know the input and</p>



<p class="wp-block-paragraph">means if I wanted to just control only which ones are allowed I can use the mask notice how the mask</p>



<p class="wp-block-paragraph">has ones in these positions and there are definitely no zeros sorry there are definitely</p>



<p class="wp-block-paragraph">no ones in any position where a mask had a zero so the mask can kind of like you know mute or mask</p>



<p class="wp-block-paragraph">or control the input pattern if that makes sense hopefully another thing we could do if we wanted</p>



<p class="wp-block-paragraph">if one bit exists. Let me go ahead and clear this real fast. I&#8217;m going to just do maybe four</p>



<p class="wp-block-paragraph">bits this time. So we could obviously do an and against four zeros, and this would result in just,</p>



<p class="wp-block-paragraph">you know, a resulting pattern of zero. So this is not super useful. The result would just</p>



<p class="wp-block-paragraph">definitely be four zeros. But notice again how the second pattern is sort of controlling what&#8217;s</p>



<p class="wp-block-paragraph">allowed to go through from the first pattern. Suppose I wanted to check to see if that particular</p>



<p class="wp-block-paragraph">particular bit was on or off.</p>



<p class="wp-block-paragraph">All I have to do is mask it with a one in the correct pattern.</p>



<p class="wp-block-paragraph">So, you know, the second bit that I just wrote down on the bottom row,</p>



<p class="wp-block-paragraph">I just want to see if that second bit is on or off in the input pattern.</p>



<p class="wp-block-paragraph">I don&#8217;t care about any of the other bits.</p>



<p class="wp-block-paragraph">That means the result will be this.</p>



<p class="wp-block-paragraph">So now it&#8217;s much more easy for me to see if that bit is on.</p>



<p class="wp-block-paragraph">I could just compare the value of those bits to a regular integer.</p>



<p class="wp-block-paragraph">Like, for example, if we consider that this was the one and this was the two</p>



<p class="wp-block-paragraph">considered that this was the one and this was the two and this was the four or sorry four and then</p>



<p class="wp-block-paragraph">the eight I could just ask now if the final value equals two and then I would know if that bit was</p>



<p class="wp-block-paragraph">on or not in the original pattern and so if I wanted to check to see if this other you know</p>



<p class="wp-block-paragraph">bit was on I can move this over here and set that back to a zero so the resulting pattern would be</p>



<p class="wp-block-paragraph">zeros then I&#8217;d ask myself is the resulting value equal to four no it&#8217;s equal to zero and so then</p>



<p class="wp-block-paragraph">Another thing you can do that I&#8217;m going to talk about in a future video is just sort of shift the bits over.</p>



<p class="wp-block-paragraph">You could, instead of checking to see if the value was a 4 or like a direct integer,</p>



<p class="wp-block-paragraph">you could just sort of shift over a certain number of spots and then check to see if it was equal to 1 or 0.</p>



<p class="wp-block-paragraph">Let me put this 1 back over into its original position just so that we&#8217;ll have something that had a 1.</p>



<p class="wp-block-paragraph">is one from uh you know the right side if it&#8217;s one to the left from the right side</p>



<p class="wp-block-paragraph">then i could just shift all the bits one to the right and end up with a pattern that is zero zero</p>



<p class="wp-block-paragraph">zero one i&#8217;m not going to talk about bit shifting operations in this video but just know that you can</p>



<p class="wp-block-paragraph">and you&#8217;ll see more of it in a future video so then you know this is another way to check to</p>



<p class="wp-block-paragraph">see if a bit was on first you do a mask for that bit and then you shift bits and then you just</p>



<p class="wp-block-paragraph">check to see if the final value is a zero or one which may or may not feel easier than checking for</p>



<p class="wp-block-paragraph">or may not feel easier than checking for an actual integer in your program.</p>



<p class="wp-block-paragraph">Okay, so we&#8217;ve done OR and also AND. The next bit pattern is called a NOT, which is really easy.</p>



<p class="wp-block-paragraph">It&#8217;s literally just an inversion of the original bit pattern. So for the NOT, we don&#8217;t really take</p>



<p class="wp-block-paragraph">two bits against each other. We just take an input bit and we just invert it. We&#8217;ll just say</p>



<p class="wp-block-paragraph">So that&#8217;s a knot. Pretty easy. We could also knot, you know, a random bit pattern with Ls.</p>



<p class="wp-block-paragraph">So I swear, somebody&#8217;s going to show up and this is their first computer science video.</p>



<p class="wp-block-paragraph">They&#8217;re going to go tell their parents, hey, there&#8217;s Ls in computer science.</p>



<p class="wp-block-paragraph">So sorry. I&#8217;m so sorry. Okay. So I got four there. So if I knot those, then that&#8217;s pretty easy.</p>



<p class="wp-block-paragraph">It&#8217;s just going to be the opposite, you know, an inversion.</p>



<p class="wp-block-paragraph">you know, an inversion.</p>



<p class="wp-block-paragraph">One, zero, one, zero.</p>



<p class="wp-block-paragraph">Let me just double check that I did that correctly.</p>



<p class="wp-block-paragraph">Yeah, so that&#8217;s the knot pattern.</p>



<p class="wp-block-paragraph">No big deal.</p>



<p class="wp-block-paragraph">Pretty easy.</p>



<p class="wp-block-paragraph">So then maybe the next thing that we can talk about is the nor,</p>



<p class="wp-block-paragraph">which just means not or.</p>



<p class="wp-block-paragraph">So let me draw that out real fast just to show you what I&#8217;m talking about.</p>



<p class="wp-block-paragraph">So if we do nor, pretty much you can imagine first taking the or and then knotting it.</p>



<p class="wp-block-paragraph">So inverting the or.</p>



<p class="wp-block-paragraph">the OR. So for example, if we have two bits here, actually, let me, let me do, let me do a</p>



<p class="wp-block-paragraph">sequential counter. Cause I think that&#8217;s more fun. I&#8217;m counting right now from one to a three</p>



<p class="wp-block-paragraph">or a actually, I do that in the last one. I started with zero. I hope let&#8217;s count from zero</p>



<p class="wp-block-paragraph">to three. So zero and then one and then two and then three. So I&#8217;m counting in binary.</p>



<p class="wp-block-paragraph">two input bits and we&#8217;re going to do a nor then the first thing we probably want to do is take</p>



<p class="wp-block-paragraph">the or operator so that would be a zero here i&#8217;ll just put or in parentheses just to let you know</p>



<p class="wp-block-paragraph">that this is kind of a nice first step you could memorize nor if you wanted to but i don&#8217;t i don&#8217;t</p>



<p class="wp-block-paragraph">really remember how to do it without doing these steps so uh it&#8217;s going to be ones for everything</p>



<p class="wp-block-paragraph">else because in the or you get a one if either of those is a one and then uh the next step is you</p>



<p class="wp-block-paragraph">the or i&#8217;ll just put nor here just to let you well just to let you know that you&#8217;re uh well i</p>



<p class="wp-block-paragraph">don&#8217;t know if i put nor then it kind of sounds like i&#8217;m norring that one bit doesn&#8217;t it so maybe</p>



<p class="wp-block-paragraph">here i&#8217;ll say uh not just to let you know that this is just one step against the previous bit</p>



<p class="wp-block-paragraph">so the knot is uh just going to be an inversion and so the nor of zero zero is one the nor of zero</p>



<p class="wp-block-paragraph">nor of 1 1 is 0 and that&#8217;s how you do a nor and all of these logical or bitwise</p>



<p class="wp-block-paragraph">operators can be used in circuits and circuit design and just you know other</p>



<p class="wp-block-paragraph">types of logical operations I&#8217;m gonna move on let&#8217;s see the next one is gonna</p>



<p class="wp-block-paragraph">be XOR that I wanted to talk about in this video so what is XOR it just means</p>



<p class="wp-block-paragraph">exclusive or so it&#8217;s a little bit more complicated than or this is actually a</p>



<p class="wp-block-paragraph">one because it has a history with neural networks. When you have a neural network that does not have</p>



<p class="wp-block-paragraph">more than one, or sorry, if you have a neural network that does not have any hidden layers,</p>



<p class="wp-block-paragraph">like if you just have an input layer and an output layer, then the neural network should</p>



<p class="wp-block-paragraph">actually not be able to solve XOR. It should not be able to learn it. You have to increase the</p>



<p class="wp-block-paragraph">topology of the neural network in some way, make it a little bit more complicated. For example,</p>



<p class="wp-block-paragraph">one or more middle layers between the input and the output layers. If you understand neural</p>



<p class="wp-block-paragraph">networks, it&#8217;s just kind of fun to know, oh, XOR stumps a shallow network and kind of starts to</p>



<p class="wp-block-paragraph">prove that deep networks might be a little bit smarter or deepish at least. Okay. So XOR,</p>



<p class="wp-block-paragraph">let&#8217;s start off by counting here. I&#8217;m going to do zero and zero, and then this is the number one,</p>



<p class="wp-block-paragraph">and this is the number two, and this is the number three. And exclusive OR just basically means</p>



<p class="wp-block-paragraph">just basically means an or but if both of the bits are one then it&#8217;s a zero so that means</p>



<p class="wp-block-paragraph">either of the bits can be a one to produce a one but it must be exclusive the bit that is a one</p>



<p class="wp-block-paragraph">can&#8217;t also be next to another bit that&#8217;s a one so let me show you so in is in a double zero</p>



<p class="wp-block-paragraph">the answer is just going to be a zero in a zero and one the answer is going to be a one in a one</p>



<p class="wp-block-paragraph">exclusive, the one is it has a, it has a buddy or a partner.</p>



<p class="wp-block-paragraph">It&#8217;s not an exclusive one.</p>



<p class="wp-block-paragraph">So we&#8217;ll say that that&#8217;s a zero.</p>



<p class="wp-block-paragraph">So that&#8217;s the XOR.</p>



<p class="wp-block-paragraph">I don&#8217;t know.</p>



<p class="wp-block-paragraph">You could put like a, a, a not on top of that or an and on top of that or whatever</p>



<p class="wp-block-paragraph">you wanted to do.</p>



<p class="wp-block-paragraph">And we can make stuff that&#8217;s a lot more complicated, but these are the basics of</p>



<p class="wp-block-paragraph">or and not XOR and NOR as bitwise operators.</p>



<p class="wp-block-paragraph">So thank you for watching this video.</p>



<p class="wp-block-paragraph">That&#8217;s all I have to say for now.</p>



<p class="wp-block-paragraph">See you in the next one.</p>



<p class="wp-block-paragraph">Hope you learned a little bit and had a little bit of fun.</p>



<p class="wp-block-paragraph">I&#8217;m out.</p>



<p class="wp-block-paragraph">social media website that you&#8217;re looking at right now it would really mean the world to me and it&#8217;ll</p>



<p class="wp-block-paragraph">help make more videos and grow this community so we&#8217;ll be able to do more videos longer videos</p>



<p class="wp-block-paragraph">better videos or just i&#8217;ll be able to keep making videos in general so please do do me a kindness</p>



<p class="wp-block-paragraph">and uh and subscribe you know sometimes i&#8217;m sleeping in the middle of the night and i just</p>



<p class="wp-block-paragraph">wake up because i know somebody subscribed or followed it just wakes me up and i get filled</p>



<p class="wp-block-paragraph">with joy that&#8217;s exactly what happens every single time so you could do it as a nice favor to me or</p>



<p class="wp-block-paragraph">it as a nice favor to me or you could you could troll me if you want to just wake me up in the</p>



<p class="wp-block-paragraph">middle of the night just subscribe and then i&#8217;ll i&#8217;ll just wake up i promise that&#8217;s what will</p>



<p class="wp-block-paragraph">happen also uh if you look at the middle of the screen right now you should see a qr code which</p>



<p class="wp-block-paragraph">you can scan in order to go to the website which i think is also named somewhere at the bottom of</p>



<p class="wp-block-paragraph">this video and it&#8217;ll take you to my main website where you can just kind of like see all the videos</p>



<p class="wp-block-paragraph">i published and the services and tutorials and things that i offer and all that good stuff and</p>



<p class="wp-block-paragraph">if you have a suggestion for uh uh clarifications or errata or just future videos that you want to</p>



<p class="wp-block-paragraph">see please leave a comment or if you just want to say hey what&#8217;s up what&#8217;s going on you know</p>



<p class="wp-block-paragraph">just send me a comment whatever i also wake up for those in the middle of the night i get i wake up</p>



<p class="wp-block-paragraph">in a cold sweat and i&#8217;m like it would really it really mean the world to me i would really</p>



<p class="wp-block-paragraph">appreciate it so again thank you so much for watching this video and um enjoy the cool music</p>



<p class="wp-block-paragraph">the cool music as I fade into the darkness which is coming for us all.</p>



<p class="wp-block-paragraph">Thank you.</p>
<p>The post <a href="https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/">Master Bitwise Operators: OR, AND, NOT, XOR, NOR for Beginners</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-bitwise-operators-or-and-not-xor-nor-for-beginners/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
