Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

From Groovy 1.0 beta 10, Groovy supports bitwise operations:
<<. >>, >>>, |, &, ^, and ~.

Operator Symbol

Meaning

<<

Bitwise Left Shift Operator

>>

Bitwise Right Shift Operator

>>>

Bitwise Unsigned Right Shift Operator

|

Bitwise Or Operator

&

Bitwise And Operator

^

Bitwise Xor Operator

~

Bitwise Negation Operator

<<=

Bitwise Left Shift Assign Operator

>>=

Bitwise Right Shift Assign Operator

>>>=

Bitwise Unsigned Right Shift Assign Operator

|=

Bitwise Or Assign Operator

&=

Bitwise And Assign Operator

^=

Bitwise Xor Operator

For example,

Code Block
java
java
assert (1 << 2) == 4         // bitwise left shift
assert (4 >> 1) == 2         // bitwise right shift
assert (15 >>> 1) == 7       // bitwise unsigned right shift
assert (3 | 6) == 7          // bitwise or
assert (3 & 6) == 2          // bitwise and
assert (3 ^ 6) == 5          // bitwise xor
int mostlyOnes = 0xFFFFFFFE
assert ~mostlyOnes == 1      // bitwise negation