Bitwise Operations |
From Groovy 1.0 beta 10, Groovy supports bitwise operations: (从grovvy1.0beta10开始支持)
<<. >>, >>>, |, &, ^, and ~.
_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
2005年06月06日 1:06 PM 翻译!