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,
Labels
3 Comments
Hide/Show CommentsMay 25, 2006
Karsten Tinnefeld
Groovy hex numbers are seemingly fixed length no more.
as of jsr-05 yields
Dec 30, 2008
Ben Walding
Mar 21, 2008
Pascal Chouinard says:
I have the same error, when changing the last line for the following it works: ...
I have the same error, when changing the last line for the following it works:
assert (int)~0xFFFFFFFE == 1 // bitwise negation
It seems the number is evaluated to a long:
println 0xFFFFFFFE.class
output: class java.lang.Long
Dec 31, 2008
Paul King
Thanks for the comments - updated to avoid confusion. Yes, anything above 0x7FFFFFFF will normally be "coerced" to Long.