groovy-位运算
2013-10-02 01:20 Rollen Holt 阅读(808) 评论(0) 编辑 收藏 举报从Groovy 1.0 beta 10开始,Groovy支持位运算:<<. >>, >>>, |, &, ^, 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 |
小例子:
1 |
assert ( 1 << 2 ) == 4 // bitwise left shift |
2 |
assert ( 4 >> 1 ) == 2 // bitwise right shift |
3 |
assert ( 15 >>> 1 ) == 7 // bitwise unsigned right shift |
4 |
assert ( 3 | 6 ) == 7 // bitwise or |
5 |
assert ( 3 & 6 ) == 2 // bitwise and |
6 |
assert ( 3 ^ 6 ) == 5 // bitwise xor |
7 |
int mostlyOnes = 0xFFFFFFFE |
8 |
assert ~mostlyOnes == 1 // bitwise negation |
==============================================================================
本博客已经废弃,不在维护。新博客地址:http://wenchao.ren
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员
==============================================================================
![](http://service.t.sina.com.cn/widget/qmd/1882500857/8c17d4b5/1.png)