0

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?

user3202188
  • 131
  • 7

2 Answers2

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
  • 378,987
  • 63
  • 458
  • 590
0

It is -1 in Two's complement. The compiler is free to choose other representations.

Klas Lindbäck
  • 32,669
  • 4
  • 56
  • 80
  • 1
    ...but no compiler in use today actually does. :) – John Zwinck Jan 16 '14 at 11:14
  • @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