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?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
user3202188
  • 131
  • 1
  • 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
  • 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
    ...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