Java: What does ~ mean

Martijn Courteaux picture Martijn Courteaux · Sep 27, 2009 · Viewed 51.7k times · Source

In this Java source code I have this line:

if ((modifiers & ~KeyEvent.SHIFT_MASK) != 0) ....

What does the tilde ~ mean?

Answer

Richard picture Richard · Sep 27, 2009

The Tilde (~) performs a bitwise complement of a numerical value in Java.

See: Bitwise complement (~): inverts ones and zeroes in a number