I was reading about two's complement, I understand this method is most efficient, but there might be some disadvantages too. I could not find any disadvantages, Is there any situation where the conversion to two's complement could fail to represent the number correctly?
Asked
Active
Viewed 6,234 times
5
-
I guess the whole electronic world rely on 2's compliment for representing numbers. It is a full proof concept and works well as long as you are working within the boundary of the available memory. – Gyanendra Dwivedi Sep 23 '13 at 05:30
2 Answers
5
Two's complement is awesome - that's why everyone uses it. The biggest disadvantage is that if you try to negate the lowest representable value, you get an overflow. With one's complement or sign and magnitude, that doesn't happen.

user2357112
- 260,549
- 28
- 431
- 505
-
-
3@Dudeson: No. For example, in 32-bit two's complement, the lowest representable value is -2^31, while the highest representable value is 2^31-1. The highest representable value can be negated just fine, while negating the lowest possible value produces an overflow. In C or C++, this is undefined behavior; in most other languages with fixed-width signed ints, negating -2^31 leaves it unchanged. – user2357112 Aug 21 '16 at 19:07
1
With "two complement"-notation you can't compare the size of two Integers with very simple logic operators (at lowest level hardware). Thats the reason why the exponent in IEEE Standard for Floating-Point Arithmetic (IEEE 754) is not represented in "two complement" but in "biased" notation.

user__42
- 543
- 4
- 13