0

I was learning about bitwise operators and I learnt that complement of 0 is 1 and 1 is 0. But when I tried using ~0 on IDLE, it printed -1 and when i typed ~1 it gave -2..

  • 2
    Although it's asking a slightly different question, this answers yours entirely? [The tilde operator in Python](https://stackoverflow.com/questions/8305199/the-tilde-operator-in-python) – Grismar Jan 18 '22 at 05:46
  • Does this answer your question? [Why the binary representation is different from python compiler than what we know on paper?](https://stackoverflow.com/questions/62332193/why-the-binary-representation-is-different-from-python-compiler-than-what-we-kno) – MisterMiyagi Jan 18 '22 at 05:53
  • Does this answer your question? [Confusion with 1's compliment binary representation](https://stackoverflow.com/questions/63886277/confusion-with-1s-compliment-binary-representation) – MisterMiyagi Jan 18 '22 at 05:59

1 Answers1

0
-1 is 0-1 => 00..00-00...01  = 1..11

So, as long as you consider some finite width (width is the size of integer or binary form you are using,4,8 ....),it is true that:

 00..00 =~11..11 

then, the following also be true:

~0=-1
Ixtiyor Majidov
  • 301
  • 4
  • 11