Rexx - 位運算子



Groovy 提供了四個位運算子。以下是 Groovy 中可用的位運算子。

序號 運算子和描述
1

bitand

這是按位“與”運算子

2

bitor

這是按位“或”運算子

3

bitxor

這是按位“異或”或“排他或”運算子

以下是展示這些運算子的真值表:

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 
rexx_operators.htm
廣告

© . All rights reserved.