What does the "~" operator do in java as in: byte b =~5 + 1
?
When the result is sent to standard out System.out.print(b)
it prints '-5'
but I don't know why or what it represents.
What does the "~" operator do in java as in: byte b =~5 + 1
?
When the result is sent to standard out System.out.print(b)
it prints '-5'
but I don't know why or what it represents.
It's the bitwise complement operator. Since java uses two's complement to represent negative numbers, ~x + 1
is equivalent to -x
.