0

I apologize to post this but I couldn't exactly find something that made sense. My basic understanding is that putting "~" in front of a number adds 1 and it turns to a negative number but I know that's not all to it. Does anyone know a simple way to explain it? It would be greatly appreciated!!

Ticci
  • 1
  • It is hard to reason about the logic of `~` from a pure integer point of view. You have to start interpreting your integer as the series of bits it is represented with. Sometimes there are some correlations that translate over to the integers but most of the time the bitwise operators only make sense on the actual bits. – Zabuzard Jan 25 '21 at 14:58
  • https://docs.oracle.com/javase/specs/jls/se14/html/jls-15.html#jls-15.15.5 "In all cases, `~x` equals `(-x)-1`." The simplest description of what it does is that it it flips all of the bits. – Andy Turner Jan 25 '21 at 14:59
  • It is the 'inverse'-operator. Read about how negative numbers are manifested in digital computers. – paladin Jan 25 '21 at 14:59
  • @paladin there is no such thing as the "inverse" operator. It is the *Bitwise Complement Operator*. – Andy Turner Jan 25 '21 at 15:03

0 Answers0