posted 6 years ago

Taken from Oracle's Java Tutorial Pages

"The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension."

"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"."

"The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension."

"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"."

Keith Rainey

OCPJP6

posted 6 years ago

You can learn about all the operators in Java from This Tutorial. The ~ is a 'bitwise compliment' operator, which inverts the bit-value for each binary bit in a number. The >>> is a a bit shift operator that moves a 0 in to the 'sign bit' (the left bit position) essentially forcing it to be positive.

So what are the effects of these operators? The best way to see that is to convert your numbers to their binary representation then perform the operations by inverting and shifting as appropriate.

So what are the effects of these operators? The best way to see that is to convert your numbers to their binary representation then perform the operations by inverting and shifting as appropriate.

Steve