How can I substract 253 from 175(175-253) through 2's complement method?

105 Views Asked by At

For 2's complement, substraction process by computer.

176-253=176+(-253)

176=10110000

253=11111101

253(inverse)=00000010

253(complement)=00000010+1=00000011

-253=253(complement)=00000011

176+(-253)=10110000+00000011=10110011=179?

but in fact 176-253=-77

is anybody tell me what's wrong here?

1

There are 1 best solutions below

4
heijp06 On

With 8 bits you can only represent numbers from -128 to 127 inclusive in 2's complement. Both your numbers lie outside that range. You would need at least nine bits to do the calculation you want to do.

In 2's complement the most significant bit (MSB, the first bit from the left), indicates the sign, 1 for negative numbers and 0 for non-negative numbers. The value:

00000011

is not -253, but is 3.

Doing your calculation in 9 bits yields:

176 = 010110000
253 = 011111101

253(inverse) = 100000010
253(complement) = 100000010+1=100000011

-253 = 253(complement) = 100000011
176+(-253) = 010110000 + 100000011 = 110110011 = -77

Note that all the negative numbers have MSB=1 and all the non-negative numbers have MSB=0.