Rexx - Bitwise Operators


Advertisements

Groovy provides four bitwise operators. Below are the bitwise operators available in Groovy.

Sr.No. Operator & Description
1

bitand

This is the bitwise “and” operator

2

bitor

This is the bitwise “or” operator

3

bitxor

This is the bitwise “xor” or Exclusive or operator

Following is the truth table showcasing these operators −

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

Example

The following program shows how the various operators can be used.

/* 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)))

The output of the above program will be −

0011001000110001
001100110011010000110111
001100100011000000110111
001100110011010100110111                     
000000010000010100110111 
rexx_operators.htm
Advertisements