Bitwise operations: Difference between revisions
Content added Content deleted
No edit summary |
(J: add a minimal bit of description) |
||
Line 630: | Line 630: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Here are the "bitwise operators": |
|||
<lang j>bAND=: 17 b. NB. 16+#.0 0 0 1 |
<lang j>bAND=: 17 b. NB. 16+#.0 0 0 1 |
||
bOR=: 23 b. NB. 16+#.0 1 1 1 |
bOR=: 23 b. NB. 16+#.0 1 1 1 |
||
Line 638: | Line 641: | ||
bRAshift=: 34 b.~ - |
bRAshift=: 34 b.~ - |
||
bLrot=: 32 b.~ |
bLrot=: 32 b.~ |
||
bRrot=: 32 b.~ - |
bRrot=: 32 b.~ -</lang> |
||
And here is a routine which takes a list of bitwise operators and two numbers and displays a table of results from combining those two numbers with each of the operators: |
|||
⚫ | |||
⚫ | |||
: |
: |
||
smoutput (((":x),"1' ',.(>u),.' '),"1":y),"1' => ',"1'.X'{~#:x u`:0 y |
smoutput (((":x),"1' ',.(>u),.' '),"1":y),"1' => ',"1'.X'{~#:x u`:0 y |
||
)</lang> |
|||
) |
|||
And here they are in action: |
|||
254 bAND`bOR`bXOR`b1NOT`bLshift`bRshift`bRAshift`bLrot`bRrot bitwise 3 |
<lang j> 254 bAND`bOR`bXOR`b1NOT`bLshift`bRshift`bRAshift`bLrot`bRrot bitwise 3 |
||
254 bAND 3 => ............................X. |
254 bAND 3 => ............................X. |
||
254 bOR 3 => ......................XXXXXXXX |
254 bOR 3 => ......................XXXXXXXX |