Skip to end of metadata
Go to start of metadata

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,

  • No labels

3 Comments

  1.   Groovy hex numbers are seemingly fixed length no more.

    as of jsr-05 yields

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

  3. Thanks for the comments - updated to avoid confusion. Yes, anything above 0x7FFFFFFF will normally be "coerced" to Long.