<?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>signed integers Archives - NeuralLantern.com</title>
	<atom:link href="https://www.NeuralLantern.com/tag/signed-integers/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.NeuralLantern.com/tag/signed-integers/</link>
	<description></description>
	<lastBuildDate>Sun, 25 May 2025 07:56:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.NeuralLantern.com/wp-content/uploads/2025/04/cropped-2025-04-04-Lantern-03-32x32.png</url>
	<title>signed integers Archives - NeuralLantern.com</title>
	<link>https://www.NeuralLantern.com/tag/signed-integers/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Master Two&#8217;s Complement: Convert &#038; Subtract Negative Binary Numbers</title>
		<link>https://www.NeuralLantern.com/master-twos-complement-convert-subtract-negative-binary-numbers/</link>
					<comments>https://www.NeuralLantern.com/master-twos-complement-convert-subtract-negative-binary-numbers/#respond</comments>
		
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Sun, 18 May 2025 22:53:54 +0000</pubDate>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Conversions]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[binary conversion]]></category>
		<category><![CDATA[binary math]]></category>
		<category><![CDATA[binary numbers]]></category>
		<category><![CDATA[binary subtraction]]></category>
		<category><![CDATA[coding for beginners]]></category>
		<category><![CDATA[computer science basics]]></category>
		<category><![CDATA[negative numbers binary]]></category>
		<category><![CDATA[programming tutorials]]></category>
		<category><![CDATA[signed integers]]></category>
		<category><![CDATA[two's complement]]></category>
		<guid isPermaLink="false">https://www.NeuralLantern.com/?p=110</guid>

					<description><![CDATA[<p>Learn two's complement to represent negative binary numbers with easy examples. Master sign bits &#038; subtraction. Subscribe!</p>
<p>The post <a href="https://www.NeuralLantern.com/master-twos-complement-convert-subtract-negative-binary-numbers/">Master Two&#8217;s Complement: Convert &amp; Subtract Negative Binary Numbers</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 Two&#039;s Complement: Convert &amp; Subtract Negative Binary Numbers" width="1380" height="776" src="https://www.youtube.com/embed/i2tfzMqlewQ?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 conquer negative numbers in binary? This fun, beginner-friendly tutorial breaks down two&#8217;s complement with step-by-step examples (-109, -29) and shows how to convert, pad, and subtract in binary. Learn sign bits, carry bits, and avoid common mistakes. Subscribe for more coding tips and tech tutorials that make learning a blast! Scan the QR code for more resources and join our community!</p>



<p class="wp-block-paragraph">Introduction to Two&#8217;s Complement 00:00:00<br>Signed vs. Unsigned Integers 00:00:28<br>Sign Bit Explanation 00:01:55<br>Positive and Negative Representation 00:02:06<br>Range of Signed Integers 00:02:48<br>Padding Signed Integers 00:05:36<br>Converting to Negative (Example: -109) 00:07:00<br>Binary Addition and Carry Bits 00:10:16<br>Correcting Conversion Mistakes 00:16:38<br>Converting Negative 29 00:13:32<br>Subtraction Using Two&#8217;s Complement 00:18:21<br>Adding Binary Numbers (109 &#8211; 29) 00:20:41<br>Verifying Results 00:23:56<br>Conclusion and Call to Action 00:25:40</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 there! Let&#8217;s talk about representing negative numbers in binary.</p>



<p class="wp-block-paragraph">We&#8217;re going to use a system called 2&#8217;s complement which is going to allow us to represent signed integers,</p>



<p class="wp-block-paragraph">which means there will be a positive sign or a negative sign on the integer</p>



<p class="wp-block-paragraph">and we&#8217;ll still be able to do it in pure binary.</p>



<p class="wp-block-paragraph">So let me talk a little bit about what I mean first here.</p>



<p class="wp-block-paragraph">signed and unsigned okay so if i just type the number 14 by itself that is uh that&#8217;s an unsigned</p>



<p class="wp-block-paragraph">integer we don&#8217;t really know if it&#8217;s positive or negative like do we know that it&#8217;s negative 14 or</p>



<p class="wp-block-paragraph">do we know that it&#8217;s positive 14 right so the sign is what lets us know if something is positive or</p>



<p class="wp-block-paragraph">negative okay so if i if i type a number in binary let&#8217;s just do a pure binary number one two three</p>



<p class="wp-block-paragraph">if you know how to convert binary to decimal you probably recognize right away that this is just</p>



<p class="wp-block-paragraph">the number zero even if we add a couple of bits here that&#8217;s just like the number three</p>



<p class="wp-block-paragraph">and so this is the number three but so far if if you haven&#8217;t learned signed integers in twos</p>



<p class="wp-block-paragraph">complement or in binary then you don&#8217;t really know that there&#8217;s a sign you just kind of assume</p>



<p class="wp-block-paragraph">that the number is positive by default if you&#8217;re not using twos complement and you&#8217;re just saying</p>



<p class="wp-block-paragraph">and you&#8217;re just saying like well let&#8217;s just do a bunch of binary you know digits then yeah it&#8217;s a</p>



<p class="wp-block-paragraph">safe assumption that the the sign is positive but we&#8217;ll use two&#8217;s complement which starts with the</p>



<p class="wp-block-paragraph">idea that the highest bit the leftmost bit the bit with the height you know the most power that&#8217;s</p>



<p class="wp-block-paragraph">going to turn into the sign that&#8217;s that&#8217;s going to turn into the plus or the minus so like you</p>



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



<p class="wp-block-paragraph">So this means that we have to decide, you know, does a zero mean positive or does it</p>



<p class="wp-block-paragraph">mean negative or what means what?</p>



<p class="wp-block-paragraph">So in two&#8217;s complement, we&#8217;ll say that zero is positive and one is negative.</p>



<p class="wp-block-paragraph">So you can see right here that we&#8217;re still actually representing the number three, but</p>



<p class="wp-block-paragraph">it&#8217;s positive three for sure because this sign bit right here is zero.</p>



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



<p class="wp-block-paragraph">Once we decide to represent two&#8217;s complement, then we can say that for sure.</p>



<p class="wp-block-paragraph">On the other hand, if we put a one here,</p>



<p class="wp-block-paragraph">then we definitely know that this number is now negative.</p>



<p class="wp-block-paragraph">However, we don&#8217;t actually know that it&#8217;s a three</p>



<p class="wp-block-paragraph">because the numbers don&#8217;t work out the same anymore</p>



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



<p class="wp-block-paragraph">So the positive numbers, they will mostly look the same.</p>



<p class="wp-block-paragraph">The negative numbers, they&#8217;ll look a lot different,</p>



<p class="wp-block-paragraph">but they&#8217;ll still be valid in order,</p>



<p class="wp-block-paragraph">you know, in terms of us being able to add them together,</p>



<p class="wp-block-paragraph">subtract them from each other and things like that.</p>



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



<p class="wp-block-paragraph">Let&#8217;s do, let&#8217;s see, what else can I tell you?</p>



<p class="wp-block-paragraph">Oh, one thing to understand is that</p>



<p class="wp-block-paragraph">One thing to understand is that in an 8-bit unsigned integer in binary, let&#8217;s say 1, 2,</p>



<p class="wp-block-paragraph">3, 4, 5, 6, 7, 8, let&#8217;s say unsigned bits, maybe I&#8217;ll just put like, maybe just some</p>



<p class="wp-block-paragraph">like V for value, all the bits are values, that means the range is 0 to 255 with 256</p>



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



<p class="wp-block-paragraph">But if we want to use a signed number, then we&#8217;ll actually have the signed bit be the first bit,</p>



<p class="wp-block-paragraph">and all the rest will be value bits.</p>



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



<p class="wp-block-paragraph">In this case, the range kind of goes down.</p>



<p class="wp-block-paragraph">Because if you think about it, every single bit, you know, represents like, you know,</p>



<p class="wp-block-paragraph">it helps towards the highest possible value that you can represent.</p>



<p class="wp-block-paragraph">If we&#8217;re using the leftmost bit, then for an 8-bit integer, that&#8217;s 128.</p>



<p class="wp-block-paragraph">integer that&#8217;s 128 that&#8217;s a value of 128 so we lose a lot off of the maximum</p>



<p class="wp-block-paragraph">integer that we can represent so the range here is I think it&#8217;s negative 20</p>



<p class="wp-block-paragraph">128 to positive 127 just keep in mind you&#8217;ll have to trust me in terms of why</p>



<p class="wp-block-paragraph">is the negative 128 bigger and the positive 127 you know smaller but that&#8217;s</p>



<p class="wp-block-paragraph">just the way it is so that means we only get these value bits here and if you if</p>



<p class="wp-block-paragraph">that um let&#8217;s see if i can do this quickly enough without screwing it up we&#8217;ll say 127 minus um</p>



<p class="wp-block-paragraph">minus negative 128 i guess that&#8217;s 255 and then also a zero but uh in terms of positive and</p>



<p class="wp-block-paragraph">negative the way this is going to work out is the zero will probably show up twice because uh</p>



<p class="wp-block-paragraph">255 possible combinations with seven bits.</p>



<p class="wp-block-paragraph">Normally you would have a range from negative, sorry, from zero to positive 255.</p>



<p class="wp-block-paragraph">And in this case, we&#8217;re just, you know, losing our range, but we can represent negative numbers.</p>



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



<p class="wp-block-paragraph">So let&#8217;s talk about doing an example real fast. Let&#8217;s see.</p>



<p class="wp-block-paragraph">I&#8217;ve got like a little notes to tell me what I should do. Okay.</p>



<p class="wp-block-paragraph">It&#8217;s important to understand that normally when you have, let&#8217;s say, let&#8217;s say you have</p>



<p class="wp-block-paragraph">like an 8-bit number and you go 1, 2, 3, 4, 5, 6, 7, 8.</p>



<p class="wp-block-paragraph">And then you have 2 bits right there and so this is like, you know, positive 3.</p>



<p class="wp-block-paragraph">If you wanted to copy that number into more bytes, like for example, if you wanted to</p>



<p class="wp-block-paragraph">take a 2-byte integer and have it copy the value of a 1-byte integer, then it&#8217;s pretty</p>



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



<p class="wp-block-paragraph">zeros to the left you&#8217;ll say one two three four five six seven eight that would work perfectly</p>



<p class="wp-block-paragraph">however if you did this with a negative number let&#8217;s say that we have a negative number</p>



<p class="wp-block-paragraph">I&#8217;m going to put some of the random patterns so that you don&#8217;t think it&#8217;s the three let&#8217;s see</p>



<p class="wp-block-paragraph">one two three four five six seven eight that&#8217;s eight total so I&#8217;m going to make that a one and</p>



<p class="wp-block-paragraph">then get rid of that so we have like eight negative number if we were going to copy that</p>



<p class="wp-block-paragraph">integer then we would copy paste it to start but then you&#8217;d have to pad with</p>



<p class="wp-block-paragraph">ones to the left one two three four five six seven eight same negative number</p>



<p class="wp-block-paragraph">more bits so be very careful about how you pad if you&#8217;re padding an unsigned</p>



<p class="wp-block-paragraph">integer then yeah you&#8217;ll always pad zeros to the left no matter what is</p>



<p class="wp-block-paragraph">happening but if you&#8217;re padding a signed integer then you have to pad differently</p>



<p class="wp-block-paragraph">signed integer you have to pad with whatever the highest bit is so in this case the highest bit was</p>



<p class="wp-block-paragraph">a zero so we do pad with zeros but then in this case the highest bit was a one so we have to pad</p>



<p class="wp-block-paragraph">with ones if you don&#8217;t do that you&#8217;re going to end up with a number that doesn&#8217;t actually make</p>



<p class="wp-block-paragraph">sense okay so now let&#8217;s work on actually converting a number to a negative number or representing a</p>



<p class="wp-block-paragraph">negative number in twos compliment okay so i&#8217;m going to write twos compliment here and then uh</p>



<p class="wp-block-paragraph">Let&#8217;s start off with the number negative 109.</p>



<p class="wp-block-paragraph">Okay, how do we do this?</p>



<p class="wp-block-paragraph">The first thing is convert it to its positive form.</p>



<p class="wp-block-paragraph">Take the absolute value. Okay.</p>



<p class="wp-block-paragraph">So we&#8217;re really just, you know, take positive form here,</p>



<p class="wp-block-paragraph">and that&#8217;s just going to be positive 109.</p>



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



<p class="wp-block-paragraph">I&#8217;ll say start with negative 109, and then we&#8217;ll take the positive form 109.</p>



<p class="wp-block-paragraph">Now we&#8217;ll convert it to binary.</p>



<p class="wp-block-paragraph">Okay, this is not a video that teaches you how to convert to binary, so I&#8217;m just going</p>



<p class="wp-block-paragraph">to try to do this in my head real fast here.</p>



<p class="wp-block-paragraph">It&#8217;s going to be, let&#8217;s see, we got 8 bits, we&#8217;ll use just 8 bits to store the number,</p>



<p class="wp-block-paragraph">and because it&#8217;s low enough and I don&#8217;t want to use that many bits, so it&#8217;s odd, so I can</p>



<p class="wp-block-paragraph">add a 1 there, but maybe for now I should find the highest bit that is less than the</p>



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



<p class="wp-block-paragraph">So this is the 128 bit right here. So that&#8217;s going to be a zero. This is the 64 bits</p>



<p class="wp-block-paragraph">I&#8217;m going to put a one there and I&#8217;m just going to say</p>



<p class="wp-block-paragraph">Mmm, maybe like</p>



<p class="wp-block-paragraph">This is like maybe not the smartest way to do it. I&#8217;ll say 109 minus 64</p>



<p class="wp-block-paragraph">Because I put a one there and then 45 so now this is 32 that&#8217;s less than 45. So I&#8217;ll put a one there and</p>



<p class="wp-block-paragraph">Then it&#8217;s going to be minus 40</p>



<p class="wp-block-paragraph">So it goes from 45 to 13.</p>



<p class="wp-block-paragraph">So then that was the 32.</p>



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



<p class="wp-block-paragraph">Is 16 less than 13?</p>



<p class="wp-block-paragraph">No, it&#8217;s not.</p>



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



<p class="wp-block-paragraph">And then the next one is going to be just four.</p>



<p class="wp-block-paragraph">Four is definitely less.</p>



<p class="wp-block-paragraph">So I&#8217;ll put a one bit there.</p>



<p class="wp-block-paragraph">And then I&#8217;ll subtract four.</p>



<p class="wp-block-paragraph">And then one, two, four.</p>



<p class="wp-block-paragraph">Oh, wait a minute.</p>



<p class="wp-block-paragraph">One, two, four, eight.</p>



<p class="wp-block-paragraph">wait a minute one two four eight sorry that was supposed to be subtracted uh subtracting eight</p>



<p class="wp-block-paragraph">because that was the eight bit uh then i want to get five so here is the four bit so i put a one</p>



<p class="wp-block-paragraph">there and then i&#8217;ll just put a one here because four plus five is equal to uh i&#8217;m sorry four plus</p>



<p class="wp-block-paragraph">one is equal to five so let&#8217;s see um it is let me just double check here one</p>



<p class="wp-block-paragraph">one let me just double check my conversion real fast it&#8217;s going to be</p>



<p class="wp-block-paragraph">the one bit plus two four plus eight six thirty two plus thirty two plus sixty</p>



<p class="wp-block-paragraph">four did I get one on nine yeah okay so I guess I did it right so convert to</p>



<p class="wp-block-paragraph">binary and that&#8217;s going to be this the next thing we&#8217;ll do is we will invert the</p>



<p class="wp-block-paragraph">bits I made a little edit jump here because I inverted the bits incorrectly</p>



<p class="wp-block-paragraph">on the first try which is sad but hey it happens the next thing we&#8217;ll do is</p>



<p class="wp-block-paragraph">but hey it happens the next thing we&#8217;ll do is we&#8217;ll invert the bits so basically you know we</p>



<p class="wp-block-paragraph">take this original sequence here and i&#8217;ll just turn every single bit uh i&#8217;ll flip it i&#8217;ll flip</p>



<p class="wp-block-paragraph">ones to zeros and zeros to ones so i&#8217;m going to go one zero zero one zero zero one zero okay so now</p>



<p class="wp-block-paragraph">we have this number invert the bits then we just have to add one so we&#8217;ll add positive one to that</p>



<p class="wp-block-paragraph">that it&#8217;s just going to be a one there at the end.</p>



<p class="wp-block-paragraph">But sometimes that might not be the case</p>



<p class="wp-block-paragraph">because what if we already had a one there</p>



<p class="wp-block-paragraph">and we had to add one to that?</p>



<p class="wp-block-paragraph">Well, we&#8217;d add one to the right side</p>



<p class="wp-block-paragraph">and it would turn into a zero</p>



<p class="wp-block-paragraph">and then it would carry a bit to the left.</p>



<p class="wp-block-paragraph">That would become a zero</p>



<p class="wp-block-paragraph">and then the carry bit would show up all the way over there.</p>



<p class="wp-block-paragraph">So I just want you to be aware of the fact that</p>



<p class="wp-block-paragraph">when you add two binary numbers together,</p>



<p class="wp-block-paragraph">you have to be careful.</p>



<p class="wp-block-paragraph">You have to add them the same way you would add decimal numbers.</p>



<p class="wp-block-paragraph">For each digit&#8217;s position,</p>



<p class="wp-block-paragraph">you have to add the two numbers together and then if they overflow then you just</p>



<p class="wp-block-paragraph">kind of wrap around to the lowest number again subtracting you know the highest</p>



<p class="wp-block-paragraph">value or sorry subtracting the base like in decimal if you add 9 and 9 the answer</p>



<p class="wp-block-paragraph">is 18 but you&#8217;re not going to write 18 in that one position you&#8217;re going to</p>



<p class="wp-block-paragraph">subtract the base which is 10 so it&#8217;ll actually be 8 and then you&#8217;ll carry the</p>



<p class="wp-block-paragraph">plus nine is equal to eight carry the one right so we&#8217;ll do the same thing in binary we&#8217;ll say</p>



<p class="wp-block-paragraph">if we ever get a one plus one when we&#8217;re adding the answer will be two but then we subtract the</p>



<p class="wp-block-paragraph">base which is two so the answer is actually zero carry a one bit keep that in mind i&#8217;m just gonna</p>



<p class="wp-block-paragraph">write it all out for you so you can kind of get a little bit of practice it&#8217;s important to to</p>



<p class="wp-block-paragraph">practice this because it&#8217;s easy to get wrong i&#8217;m going to put a bunch of dashes up at the top to</p>



<p class="wp-block-paragraph">and I&#8217;m going to say we&#8217;re going to add, you know, one number plus another number,</p>



<p class="wp-block-paragraph">put a little plus symbol over there just to try and make sure we do it the right way.</p>



<p class="wp-block-paragraph">Okay, so how do we add these?</p>



<p class="wp-block-paragraph">Well, we&#8217;ll just go to the right side.</p>



<p class="wp-block-paragraph">Zero plus one is one, no carry bit.</p>



<p class="wp-block-paragraph">One plus zero is one, no carry bit.</p>



<p class="wp-block-paragraph">Then we got a couple zeros here, no carry bit, of course.</p>



<p class="wp-block-paragraph">One plus zero is one, no carry bit.</p>



<p class="wp-block-paragraph">And then a couple zeros and then another one with no carry bit.</p>



<p class="wp-block-paragraph">Okay, so, you know, we could have done that pretty easily, but</p>



<p class="wp-block-paragraph">but well now we&#8217;re getting a taste for binary addition that might be harder later.</p>



<p class="wp-block-paragraph">So we&#8217;ll just do that for now.</p>



<p class="wp-block-paragraph">And now this is the two&#8217;s complement representation of negative 109.</p>



<p class="wp-block-paragraph">I&#8217;ll say now we have negative 109 is equal to that.</p>



<p class="wp-block-paragraph">leftmost number the most powerful sorry leftmost bit the most powerful bit is a one remember one</p>



<p class="wp-block-paragraph">always indicates negative so when you&#8217;re looking at it if your leftmost bit turns out to be a zero</p>



<p class="wp-block-paragraph">then you probably did something wrong or you had an overflow maybe um and again if we were going</p>



<p class="wp-block-paragraph">to try to you know send this number into a two byte number or an eight byte number or whatever</p>



<p class="wp-block-paragraph">uh then we would just have to pad with the sign bit so one two three four five six seven eight</p>



<p class="wp-block-paragraph">help my brain so this was this is the way it would look in a two-byte number this is the way it would</p>



<p class="wp-block-paragraph">look in a three-byte a four-byte and five six seven how many one two three four five six seven</p>



<p class="wp-block-paragraph">okay one more this is what it would look like as an eight-byte number or a quad word 64-bit number</p>



<p class="wp-block-paragraph">yeah okay so now we know how to do negative 109 okay so now let&#8217;s do a number that&#8217;s a little bit</p>



<p class="wp-block-paragraph">negative 29. So let&#8217;s say convert, or how about represent negative 29 into</p>



<p class="wp-block-paragraph">2&#8217;s complement. Okay. So first we, you know, first get the absolute value.</p>



<p class="wp-block-paragraph">So just 29. And then we have to invert the, sorry, we have to get that into binary. So</p>



<p class="wp-block-paragraph">next convert to binary. And I&#8217;m going to start with zeros, one, two, three, four, five, six,</p>



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



<p class="wp-block-paragraph">For this video, remember, we&#8217;re choosing to use one byte integers.</p>



<p class="wp-block-paragraph">But if you wanted to do a bigger one or you had to do a bigger one,</p>



<p class="wp-block-paragraph">then just, you know, keep that in mind.</p>



<p class="wp-block-paragraph">Okay, so 128 is not smaller than 29.</p>



<p class="wp-block-paragraph">64 is not.</p>



<p class="wp-block-paragraph">32 is not.</p>



<p class="wp-block-paragraph">16 is, though.</p>



<p class="wp-block-paragraph">So I&#8217;ll put a 16 bit there.</p>



<p class="wp-block-paragraph">And I&#8217;ll just subtract 16 from 29.</p>



<p class="wp-block-paragraph">29 minus 16.</p>



<p class="wp-block-paragraph">Now we&#8217;ve got 13 left.</p>



<p class="wp-block-paragraph">So 64, 32, 16.</p>



<p class="wp-block-paragraph">six four thirty two sixteen eight okay so now I&#8217;m gonna put a one bit there and</p>



<p class="wp-block-paragraph">I&#8217;m gonna subtract 8 from the remainder and then we got a five which is pretty</p>



<p class="wp-block-paragraph">easy to do eight four and then a one so now we have well zero zero zero one one</p>



<p class="wp-block-paragraph">one zero one that&#8217;s the binary number the positive or unsigned representation</p>



<p class="wp-block-paragraph">representation. So now we&#8217;ll add one. Positive one. And let&#8217;s try to do this the right way so</p>



<p class="wp-block-paragraph">that we can practice carry bits with addition a little bit. Notice how this one is already there</p>



<p class="wp-block-paragraph">on the right side. So it&#8217;s going to, we&#8217;re going to have at least one carry bit for sure.</p>



<p class="wp-block-paragraph">So then I&#8217;m going to go doop like that. And then I&#8217;m going to say that we have like, you know,</p>



<p class="wp-block-paragraph">what is the result? Put a positive sign there. And then I&#8217;m going to put a bunch of dashes</p>



<p class="wp-block-paragraph">my carry bits because I can I can forget that pretty easily. So the first thing is we add one</p>



<p class="wp-block-paragraph">and one. The answer is two, but we can&#8217;t put the number two here because it&#8217;s binary. Instead we</p>



<p class="wp-block-paragraph">need to subtract the base which is two. So two minus two is equal to zero, but then we have a</p>



<p class="wp-block-paragraph">carry bit of one. So I&#8217;m going to put a one there. The first carry bit will stay as a dash for this</p>



<p class="wp-block-paragraph">whole you know exercise because you&#8217;re not going to carry on to the first digit. So now we have</p>



<p class="wp-block-paragraph">what would have been just zero plus zero now we have one plus zero plus zero so</p>



<p class="wp-block-paragraph">that means this is going to be one and then the carry bit is just going to be</p>



<p class="wp-block-paragraph">zero because we don&#8217;t actually carry anything so then we have zero plus one</p>



<p class="wp-block-paragraph">plus zero so that&#8217;s going to be a one and then zero carry bit and then zero</p>



<p class="wp-block-paragraph">one zero is just going to be one and then there&#8217;s going to be no carry bit</p>



<p class="wp-block-paragraph">and then zero one zero again a one no carry bit because we didn&#8217;t actually</p>



<p class="wp-block-paragraph">zero zero zero and then I&#8217;m just gonna put zeros here okay so now we have</p>



<p class="wp-block-paragraph">successfully added I blew it totally blew it I always forget steps don&#8217;t</p>



<p class="wp-block-paragraph">forget the steps this is a good lesson I&#8217;m gonna leave this in the video</p>



<p class="wp-block-paragraph">because I want you to see that everybody makes mistakes and you got to practice</p>



<p class="wp-block-paragraph">practice practice especially before you have to actually do this in real life or</p>



<p class="wp-block-paragraph">or something like that.</p>



<p class="wp-block-paragraph">Next, convert to binary.</p>



<p class="wp-block-paragraph">Before you add one, I&#8217;m gonna just remove this.</p>



<p class="wp-block-paragraph">Oh my gosh.</p>



<p class="wp-block-paragraph">Next, flip the bits,</p>



<p class="wp-block-paragraph">which is gonna be 1110010.</p>



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



<p class="wp-block-paragraph">So now we take this bit flipped number</p>



<p class="wp-block-paragraph">and we will add one.</p>



<p class="wp-block-paragraph">So that&#8217;s gonna be zero, zero, zero, zero, zero, zero, zero,</p>



<p class="wp-block-paragraph">one, oh, it&#8217;s too easy.</p>



<p class="wp-block-paragraph">Maybe I got excited and I thought,</p>



<p class="wp-block-paragraph">excited and I thought, oh, it&#8217;s carry bit time.</p>



<p class="wp-block-paragraph">But even though the last edition that I did was wrong because I forgot to carry</p>



<p class="wp-block-paragraph">the or flip the bits, you still at least saw a little bit about how to carry the bits.</p>



<p class="wp-block-paragraph">Right. OK, so it&#8217;s just going to be one.</p>



<p class="wp-block-paragraph">Let me start from the right side.</p>



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



<p class="wp-block-paragraph">Let me just double check here.</p>



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



<p class="wp-block-paragraph">OK, so I got that.</p>



<p class="wp-block-paragraph">Now we have.</p>



<p class="wp-block-paragraph">negative 29 in twos compliment. Again notice if we actually tried to add those numbers up to be</p>



<p class="wp-block-paragraph">like an unsigned binary number they&#8217;re not really going to make sense because this is like 64 plus</p>



<p class="wp-block-paragraph">32 plus 3. So what would that end up being? Let&#8217;s just double check here. 64 plus 32 plus 3, 99.</p>



<p class="wp-block-paragraph">That&#8217;s not actually the number but the number is 29. So keep in mind you can&#8217;t just look at this</p>



<p class="wp-block-paragraph">unless you&#8217;re like really, really practiced.</p>



<p class="wp-block-paragraph">Okay, and again, notice that the number is 1 at the very left,</p>



<p class="wp-block-paragraph">indicating that it&#8217;s a negative number.</p>



<p class="wp-block-paragraph">Now, let&#8217;s look at how to subtract one number from another</p>



<p class="wp-block-paragraph">using 2&#8217;s complement.</p>



<p class="wp-block-paragraph">Okay, so what I want to do is I want to subtract,</p>



<p class="wp-block-paragraph">let&#8217;s say, 29 from 109.</p>



<p class="wp-block-paragraph">Okay, so let&#8217;s subtract, and I&#8217;ll just say 109 minus 29.</p>



<p class="wp-block-paragraph">109 minus 29.</p>



<p class="wp-block-paragraph">And how I would do that is basically I&#8217;ll start by just taking 109.</p>



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



<p class="wp-block-paragraph">So I&#8217;m just going to copy paste that number.</p>



<p class="wp-block-paragraph">So 109 is this and then 29, take the positive version.</p>



<p class="wp-block-paragraph">It is just, let&#8217;s see, before we flip the bits or anything,</p>



<p class="wp-block-paragraph">let me make sure that I grab the right one.</p>



<p class="wp-block-paragraph">Invert the bits, okay.</p>



<p class="wp-block-paragraph">So positive 29 is this number.</p>



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



<p class="wp-block-paragraph">is this number whoops let me put parentheses around that so it&#8217;s easy to tell and then I&#8217;ll</p>



<p class="wp-block-paragraph">put a positive sign there like that maybe like that nope nope nope nope how about this okay</p>



<p class="wp-block-paragraph">so now we have both of these numbers in positive form so now if we added 109 plus 29 that wouldn&#8217;t</p>



<p class="wp-block-paragraph">negative positive 29 that would be what we wanted right because really if you&#8217;re subtracting</p>



<p class="wp-block-paragraph">i&#8217;ll say aka</p>



<p class="wp-block-paragraph">positive 29 plus negative 29 all we really need to do is um invert the 29 and then add the result</p>



<p class="wp-block-paragraph">to 109 so that means we&#8217;ll we&#8217;ll turn positive 29 into negative 29 using two&#8217;s complement</p>



<p class="wp-block-paragraph">through the steps again but basically put it there but basically you know that&#8217;s negative 29</p>



<p class="wp-block-paragraph">so say positive 129 is equal to what i just put up here and then negative 29 is equal to</p>



<p class="wp-block-paragraph">maybe i should do the parentheses again for clarity uh is equal to this okay so you can tell</p>



<p class="wp-block-paragraph">that positive 29 is pretty pretty different from negative 29 but now we have</p>



<p class="wp-block-paragraph">29 but now we have both of those numbers so let&#8217;s see 0 1 1 0 and then we&#8217;re ready to add okay all</p>



<p class="wp-block-paragraph">we got to do is add them together next add them together maybe I should write the steps up here</p>



<p class="wp-block-paragraph">negative 29 using twos complement and then next add them together so then I&#8217;m</p>



<p class="wp-block-paragraph">going to copy paste the bits here and it&#8217;s going to be this plus this do a</p>



<p class="wp-block-paragraph">positive plus sign just to remind ourselves that we are actually adding</p>



<p class="wp-block-paragraph">and then I&#8217;m going to put a bunch of placeholders for sign bits up at the</p>



<p class="wp-block-paragraph">top and now we&#8217;ll have a little bit more fun adding numbers together maybe I&#8217;ll</p>



<p class="wp-block-paragraph">drag this down</p>



<p class="wp-block-paragraph">Oh my god. Oh, there we go. Okay. So I&#8217;ll start with the one on the right, the position on the</p>



<p class="wp-block-paragraph">right. That&#8217;s going to be one plus one equals two, but then that&#8217;s an overflow. So I&#8217;m going to</p>



<p class="wp-block-paragraph">subtract the base. So it&#8217;s going to be zero. And then don&#8217;t forget to carry the one. Oh,</p>



<p class="wp-block-paragraph">cool. More interesting. So we have one plus zero plus one. That&#8217;s going to be another two carry</p>



<p class="wp-block-paragraph">two carry the one so it&#8217;s going to be zero and then carry the one again so i&#8217;m going to put the</p>



<p class="wp-block-paragraph">carry bit up there and then again we have one plus one is equal to two so it&#8217;s going to be zero</p>



<p class="wp-block-paragraph">carry the one again zero carry the one and then finally we don&#8217;t really have a carry bit</p>



<p class="wp-block-paragraph">um so we&#8217;ll just have like a one and there&#8217;s there&#8217;s no carry so it&#8217;s going to be you know</p>



<p class="wp-block-paragraph">carry a zero and then we add these two together so it&#8217;s going to be a zero carry the one and then</p>



<p class="wp-block-paragraph">Now we have a three.</p>



<p class="wp-block-paragraph">Oh, that&#8217;s kind of nice.</p>



<p class="wp-block-paragraph">So this is an interesting edge case kind of.</p>



<p class="wp-block-paragraph">One plus one plus one is three.</p>



<p class="wp-block-paragraph">But if we subtract two, the base from it, you know, three minus two, it&#8217;s going to be one, not zero.</p>



<p class="wp-block-paragraph">So it actually is going to be a one and then carry the one on top of that.</p>



<p class="wp-block-paragraph">Then for here, let me space this over a little bit so that I can illustrate what&#8217;s going on a little bit better.</p>



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



<p class="wp-block-paragraph">definitely going to be zero and then carry the one but there&#8217;s no bit where that carried one can</p>



<p class="wp-block-paragraph">can show up on right so that one overflows it falls off the edge if this was a bigger number</p>



<p class="wp-block-paragraph">then okay we you know if we had more bits to this number then sure we would just keep carrying over</p>



<p class="wp-block-paragraph">over to the left but remember we said before that when we have a very big number let&#8217;s see</p>



<p class="wp-block-paragraph">bits it&#8217;s just ones all the way to the side that will actually help us make sure that if our final</p>



<p class="wp-block-paragraph">number is actually going to end up being positive that everything kind of like dominoes like carry</p>



<p class="wp-block-paragraph">the one carry the one carry the one carry the one carry the one all the way until one of the ones</p>



<p class="wp-block-paragraph">falls off think about it so anyway this one just is gone we don&#8217;t really care about it anymore</p>



<p class="wp-block-paragraph">the result is going to be just only eight bits because that&#8217;s the number that we started with</p>



<p class="wp-block-paragraph">bunch of zeros what is you know the final answer let&#8217;s just compute this</p>



<p class="wp-block-paragraph">real fast to decimal so this is 128 and then 64 so it&#8217;s gonna be 64 plus not 32</p>



<p class="wp-block-paragraph">but 16 so 64 plus 16 that&#8217;s gonna be oops 16 that&#8217;s gonna be 80 and now we</p>



<p class="wp-block-paragraph">just have to ask ourselves again as like a final step to double check yourself to</p>



<p class="wp-block-paragraph">what you&#8217;re doing and that you got it right is just punch up 109 minus 29 just to make sure</p>



<p class="wp-block-paragraph">109 minus 29 whoops what happened here 109 minus</p>



<p class="wp-block-paragraph">oh i think i stole my subtraction key for the annotator 109 minus 29 is 80</p>



<p class="wp-block-paragraph">so again you know if you&#8217;re if you&#8217;re trying to like you know write something down to do some</p>



<p class="wp-block-paragraph">you know taking an exam or something you definitely want to double check yourself in several ways</p>



<p class="wp-block-paragraph">As you can tell from this video alone</p>



<p class="wp-block-paragraph">I got one of these things wrong because I forgot to input the bits as a step before adding one</p>



<p class="wp-block-paragraph">So you know your final step should be actually trying to add two numbers together or subtract numbers or whatever</p>



<p class="wp-block-paragraph">You&#8217;re doing to make sure that you got the binary correct</p>



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



<p class="wp-block-paragraph">Hmm</p>



<p class="wp-block-paragraph">I guess maybe your first indication that the result was going to be positive would be that</p>



<p class="wp-block-paragraph">there&#8217;s a zero there. And just, you know, as a sanity check, you look at the top and you&#8217;re like,</p>



<p class="wp-block-paragraph">well, I was going to subtract a small number from a larger number. So the result should probably be</p>



<p class="wp-block-paragraph">positive, right? Like 29 is like way lower than 109. So it should be positive, which means the</p>



<p class="wp-block-paragraph">final result should have a zero at that leftmost position. Okay, so that&#8217;s two&#8217;s compliment,</p>



<p class="wp-block-paragraph">two&#8217;s complement how to convert numbers from positive to negative in two&#8217;s complement you</p>



<p class="wp-block-paragraph">know what the sign bit means and all that stuff and how to perform subtraction via two&#8217;s complement</p>



<p class="wp-block-paragraph">i hope you enjoyed this video thank you for watching i hope you learned a little bit of</p>



<p class="wp-block-paragraph">stuff and had a little bit of fun see you in the next video hey everybody thanks for watching this</p>



<p class="wp-block-paragraph">video again from the bottom of my heart i really appreciate it i do hope you did learn something</p>



<p class="wp-block-paragraph">If you could do me a please, a small little favor, could you please subscribe and follow this channel or these videos or whatever it is you do on the current social media website that you&#8217;re looking at right now.</p>



<p class="wp-block-paragraph">It would really mean the world to me and it&#8217;ll help make more videos and grow this community.</p>



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



<p class="wp-block-paragraph">So please do me a kindness and subscribe.</p>



<p class="wp-block-paragraph">in the middle of the night and I just wake up because I know somebody</p>



<p class="wp-block-paragraph">subscribed or followed. It just wakes me up and I get filled with joy. That&#8217;s</p>



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



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



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



<p class="wp-block-paragraph">will happen. Also if you look at the middle of the screen right now you</p>



<p class="wp-block-paragraph">should see a QR code which you can scan in order to go to the website which I</p>



<p class="wp-block-paragraph">think is also named somewhere at the bottom of this video and it&#8217;ll take you</p>



<p class="wp-block-paragraph">you to my main website where you can just kind of like see all the videos I published and the</p>



<p class="wp-block-paragraph">services and tutorials and things that I offer and all that good stuff and if you have a suggestion</p>



<p class="wp-block-paragraph">for clarifications or errata or just future videos that you want to see please leave a comment or if</p>



<p class="wp-block-paragraph">you just want to say hey what&#8217;s up what&#8217;s going on you know just send me a comment whatever I also</p>



<p class="wp-block-paragraph">wake up for those in the middle of the night I get I wake up in a cold sweat and I&#8217;m like</p>



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



<p class="wp-block-paragraph">thank you so much for watching this video and enjoy the cool music as I fade</p>



<p class="wp-block-paragraph">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-twos-complement-convert-subtract-negative-binary-numbers/">Master Two&#8217;s Complement: Convert &amp; Subtract Negative Binary Numbers</a> appeared first on <a href="https://www.NeuralLantern.com">NeuralLantern.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.NeuralLantern.com/master-twos-complement-convert-subtract-negative-binary-numbers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
