Rexx-bitwise-operators
提供:Dev Guides
Rexx-ビット演算子
Groovyは4つのビット演算子を提供します。 以下は、Groovyで使用可能なビットごとの演算子です。
Sr.No. | Operator & Description |
---|---|
1 |
bitand これはビット単位の「and」演算子です |
2 |
bitor これはビット単位の「or」演算子です |
3 |
bitxor これはビット単位の「xor」または排他的論理和演算子です |
以下は、これらの演算子を示す真理値表です-
p | q | p bitand q | p bitor q | p bitxor q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
例
次のプログラムは、さまざまな演算子の使用方法を示しています。
/*Main program*/
a = 21
b = 347
Say c2b(a)
Say c2b(b)
Say c2b(bitand(a,b))
Say c2b(bitor(a,b))
Say c2b(bitxor(a,b))
Exit
c2b: return x2b(c2x(arg(1)))
上記のプログラムの出力は次のようになります-
0011001000110001
001100110011010000110111
001100100011000000110111
001100110011010100110111
000000010000010100110111