In this Java source code I have this line:
if ((modifiers & ~KeyEvent.SHIFT_MASK) != 0) ....
What does the tilde ~
mean?
it means: if(min >= 2) someval =2; else someval =1. Its called a ternary operator See this java example too.
It is called a 'NOT' operator. It can be used to convert false to true or vice versa. By using this operator, the logical state of an operand is reversed. In simple words, it inverts the value of a boolean. Read Also: What does \n and \t mean in Java.
The Tilde (~
) performs a bitwise complement of a numerical value in Java.
See: Bitwise complement (~
): inverts ones and zeroes in a number
It is the Unary ~ Bitwise complement operator (quoting) :
See also this page on Bitwise operators on wikipedia, which states :
The bitwise NOT, or complement, is a unary operation that performs logical negation on each bit, forming the ones' complement of the given binary value. Digits which were 0 become 1, and vice versa.
For example:
NOT 0111 (decimal 7) = 1000 (decimal 8)
In many programming languages (including those in the C family), the bitwise NOT operator is "
~
" (tilde).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With