2’s Complement

2’s Complement


Hey guys this is a video on 2’s
complement for Digital Systems one. Yes I have a very tiny little cute whiteboard that I’m going to be showing you things on.
Why? because I’m lazy person, and I have a little tiny personal whiteboard that I borrowed from someone. So 2’s complement is a bit complicated at first understand because it seems like it’s absolute and utter nonsense; and you know to be fair sometimes it is, but the point of 2’s complement is so you can represent positive and negative numbers within a range; depending on the number of bits in your binary number. Now I’m going
to assume you all know how to write a common number in binary. For example, I am writing the number 11. Wow, I had to calculate it in my head. So proud. So we know, least significant bit and most significant bit. 1 plus 2 is 3, plus 8 is 11. So now 2’s complement messes around with that. because it uses that most significant bit as a sign of whether it is positive or negative. Say we have a number, in 4 bits, you know 4 places. So the range for the
2’s complement number can go from negative 2 to the N minus one to 2 to the N minus 1, minus 1. Yes, messy handwriting. So that basically means you can represent in four
bits any number between -8 and positive 7. Now you don’t necessarily need to know the range to
write something in 2’s complement, but it’s always good to know. So 0 corresponds to a positive number, and one corresponds to a negative number. Now These are our most significant bits in the numbers, so when we have a 2’s complement number this is equal to…positive 3, right here. So, you’d think that -3 would be this, right? Well, that’s not exactly accurate Why? Cause it works that way. Now the simplest way to explain how to swap something to its negative are as we say, “invert and add 1” So we have 0011, which is equal to positive 3. So we invert it and then we add on 1. Now assuming you all know how to add in binary. So that would give us 1101; and 1101 is equal to -3. Now the actual way that works out is: 5 seconds for me to erase 1101 is apparently…So you’ve
got your most significant bit and its negative so you go; this is 4 and this is 1 you actually subtract the four from the one, and that gives you your negative 3. It’s simpler just to switch something back to it’s positive number, and just calculate out things from there. Trust me, it really is. Because this is -1. 4 bits you can represent all the way up to -8 or 7 The first 1 or 0 to the left of your complete ‘binary number’ is going to be
the sign of it start getting consistent, like, 1’s or
consistent 0’s that means that’s your sign, and yeah that’s really annoying and confusing, and I understand. But that’s how 2’s complement works unfortunately Now, for those of you who are like: “But how do I represent negative 7?!” Yeah, well negative 7 is 1001. Now, if you remember from earlier that’s because we’ve got the 8, the 1 even though this is also your sign for your
negative, because we’re going to have another one over here, if we were writing this in 5 bits, that would say this is negative. So we take the 8, and we subtract it from the 1, and 1 minus 8 equals negative 7. Once again, I’m going to stress this fact, but when you’ve got…I’m gonna go with..umm negative 8 here in 2’s complement 5 bits. So, we’ve got this the one to the left of the last zero in it, see this is your last
zero this creates the number, this here is my sign. So my sign is negative, but it also is part of it, so this is a negative 16, you add that to this 8, and you get negative 8. TADA! Invert and add 1, it will save you so much stress in the
long run Trust me, repeat it as a mantra If you have something that’s in negative
form in 2’s compliment and it’s negative you see that 1 there
at the beginning of it that means it’s a negative number, just invert it, add 1 you have it as a positive number. Just
subtract those two positive numbers in binary it will be so much simpler. Now, only saying this because adding and
subtracting two’s complement can be a real pain. Overflow, Overflow doesn’t happen very often(if you’re careful), but when it does it’s a bit of a mess-up, because say you’re adding positive 5 and positive 6 in 2’s complement with most significant bits addressed as signs. You’ve got 0101 for 5 and 0110 for 6 So positive 5, plus positive 6 if you add those two together, you get 1011 that’s not the right answer because 11, positive 11 requires 5 bits too create the sign, which would be…that. Alright guys, that’s the end of the video for now because I don’t really have anything else I can tell you about
2’s complement except don’t get it mixed up with 1’s complement. and if I make a video about that, I will let you know in some sort of box, over here-ish. Otherwise, if you have any questions, just put them
in the comments below. Otherwise, Good Luck, I hope I helped :).

Leave a Reply

Your email address will not be published. Required fields are marked *