-4

Can someone help to explain what "~" does in Java? I searched but couldn't find the answers as I don't know what ~ is called. Thanks in advance. Below is an example from an open source stego program called Snow.

private int     tabpos (int n) {
    return ((n + 8) & ~7);
}
user3735871
  • 527
  • 2
  • 14
  • 31

1 Answers1

3

From Oracle documentation:

The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".

Reference: Bitwise and Bit Shift Operators

CDT
  • 10,165
  • 18
  • 66
  • 97