Computer Science, asked by alloythe, 8 months ago

Subtract (1100), from (1011), using
both I's and 2's compliment method​

Answers

Answered by sanjeevsitapur2
0

Answer:

We want to add 1100 to 1011

1100 is already positive, so its two's complement representation is the same.

Let's say we have 8 bits to represent these numbers. Se we really have

00001011 and 00110001.

To get the two's complement of 00110001 (to get its negative representation), we need to flip the bits and add one.

Why flip the bits?

Here's how a two's complement number is represented: The value of the first bit is negative 2^N (In this case, it's -2^7) The values of all the other bits is the same as their positive binary representation.

The most significant bit in the binary representation is always zero, so when we flip it to one, we're subtracting 2^N from our number. To counter the fact that we just subtracted a huge amount from the value of our number, we need to add some back. The greater our original number was (e.g. if it was 127), we would only want to add a little back (-128 + 1 = -127). Similarly, the lesser our original number was (e.g. if it was 3), we would want to add a lot back (-128 + 125 = -3). For this reason of compensation, we flip the bits.

Why add one?

The sum of all powers of two less than 2^N is 2^N - 1. And so, by flipping all the bits, we lost 1, and we now need to add it back in.

And so, the two's complement of 00110001 is 11001111.

The beauty of the two's complement system is that now we can add the two numbers together to execute the subtraction.

00001011

+11001111

11011010

To convert from two's complement to binary, we sum the negative value of the first bit (weighted by its power of two) and the positive value of all the rest.

And so, the answer is

-128 + 64 + 16 + 8 + 2 = -38

To check, the original problem was, "subtract 49 from 11".

Similar questions