Let's use our 2's complement to figure out what number is being represented here.
So I have 1111 0011.
Now, note, since this is an 8-bit signed integer and I have a 1 here, this is a negative number
and it's written using the 2's complement.
So to figure out what number it is, I can take the 2's complement of this and then note
that it's the negative version of it.
So this is 1111 0011.
Remember, to take the 2's complement, first we find the 1's complement.
Make this 1 a 0.
Make this 1 a 0.
Make this 1 a 0.
Make this 1 a 0.
That 0 is a 1.
This 0 is a 1.
That 1's a 0.
That 1's a 0.
Now there's the 1's complement.
Again, to make it the 2's complement we're going to add 1.
Remember, we're in binary, but this time it won't matter.
0 plus 1 is 1.
And then the rest of these guys will be the same.
This positive number is pretty easy to see what it is.
I've got a 1, but no 2s, a 4, and an 8.
8 plus 4 plus 1 is 13.
That means that this number is representing negative 13.
Right?
So if I have a negative value I can just take the 2's complement, find out what that value
is, and then note that I have the negative of it.
Okay, let's do one more quick example.
Let's write the 8-bit signed integer for negative 36.
So to do that, I'm going to write the 8-bit signed integer
for positive 36 and then we'll take the 2's complement.
And that will be how I represent negative 36.
So, positive 36, we've got a bunch of ways we could do this.
Let's just go for the low-hanging fruit since this is so close to one of our place values.
So here are the blanks.
Starting at the top we have the sign bit.
This is positive so it's 0.
There are no 64s in 36, but there's a 32.
And then all I have left is 4, so I put a 1 in the 4s place and positive 36 as an 8-bit
signed integer is 0010 0100.
Great.
To make that negative, or find the negative representation, we just need to take the 2's
complement, so first take the 1's complement.
0 to a 1.
0 to a 1.
1 to a 0.
0 to a 1.
0 to a 1.
1 to a 0.
0 to a 1.
And, 0 to a 1.
Okay, there's the 1's complement.
Now, remember, you have to add 1 to get to the 2's complement.
And, we've got some carrying, zero...er, sorry, 1 plus 1 is 1, er, 0 carry a 1.
1 plus 1 is 0 carry a 1.
1 plus 0 is 1.
And then I can bring down the rest of these.
And here it is.
Here is negative 36 as an 8-bit signed integer.
1101 1100.
Không có nhận xét nào:
Đăng nhận xét