When compliment of 0 was found it turned out to be -1. Why the complement of 0 is -1? Is it always -1 or does it depend on compiler?
Asked
Active
Viewed 124 times
0
-
2What do you mean by "complement" or "compliment" here? Do you mean bitwise negation? – John Zwinck Jan 16 '14 at 11:08
-
It means the operation of ~ operator – user3202188 Jan 16 '14 at 11:11
-
So yes, bitwise negation. – John Zwinck Jan 16 '14 at 11:13
2 Answers
2
The bitwise negation of 0, written in C as ~0
, is -1 only if the compiler uses two's complement to represent signed integers. So, it's a result of the way the compiler represents numbers and is not generally "true".

unwind
- 391,730
- 64
- 469
- 606
0
It is -1 in Two's complement. The compiler is free to choose other representations.

Klas Lindbäck
- 33,105
- 5
- 57
- 82
-
1
-
@John There are still legacy systems that use one's complement, but they are getting more and more rare. I usually assume two's complement when I code C. Using constructs newer than C89 is probably a greater reduction in portability than assuming two's complement. – Klas Lindbäck Jan 16 '14 at 11:21