Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

Bitwise Operations Add comment to Wiki View in Wiki Edit Wiki page Printable Version

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,

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
assert (~0xFFFFFFFE) == 1    // bitwise negation