Bitwise operations: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (ooRexx added) |
|||
Line 1,388: | Line 1,388: | ||
The only bit operators available in OpenEdge are the GET-BITS() and PUT-BITS() functions. These functions can be used to implement all bitwise operators. |
The only bit operators available in OpenEdge are the GET-BITS() and PUT-BITS() functions. These functions can be used to implement all bitwise operators. |
||
=={{header|ooRexx}}== |
|||
<lang ooRexx>/* ooRexx ************************************************************* |
|||
/ Bit Operations work as in Rexx (of course) |
|||
* Bit operations are performed up to the length of the shorter string. |
|||
* The rest of the longer string is copied to the result. |
|||
* ooRexx introduces the possibility to specify a padding character |
|||
* to be used for expanding the shorter string. |
|||
* 10.11.2012 Walter Pachl taken over from REXX and extended for ooRexx |
|||
**********************************************************************/ |
|||
a=21 |
|||
b=347 |
|||
Say ' a :'c2b(a) ' 'c2x(a) |
|||
Say ' b :'c2b(b) c2x(b) |
|||
Say 'bitand(a,b) :'c2b(bitand(a,b)) c2x(bitand(a,b)) |
|||
Say 'bitor(a,b) :'c2b(bitor(a,b)) c2x(bitor(a,b)) |
|||
Say 'bitxor(a,b) :'c2b(bitxor(a,b)) c2x(bitxor(a,b)) |
|||
p='11111111'B |
|||
Say 'ooRexx only:' |
|||
Say 'a~bitor(b,p):'c2b(a~bitor(b,p)) c2x(a~bitor(b,p)) |
|||
Exit |
|||
c2b: return x2b(c2x(arg(1)))</lang> |
|||
Output: |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 1,399: | Line 1,423: | ||
print("Right shift: ",a>>b); |
print("Right shift: ",a>>b); |
||
}</lang> |
}</lang> |
||
<pre> |
|||
a :0011001000110001 3231 |
|||
b :001100110011010000110111 333437 |
|||
bitand(a,b) :001100100011000000110111 323037 |
|||
bitor(a,b) :001100110011010100110111 333537 |
|||
bitxor(a,b) :000000010000010100110111 010537 |
|||
ooRexx only: |
|||
a~bitor(b,p):001100110011010111111111 3335FF |
|||
</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |