Jump to content

Bitwise operations: Difference between revisions

Added befunge-93 entry
m (→‎{{header|REXX}}: added wording to the REXX section boxed comment.)
(Added befunge-93 entry)
Line 723:
<lang beeswax>A ROL B = A<<(B%64)+A>>>(64-B%64)
A ROR B = A>>>(B%64)+A<<(64-B%64)</lang>
 
=={{header|Befunge}}==
<lang befunge>> v MCR >v
1 2 3 4 5 6>61g-:| 8 9
>&&\481p >88*61p371p >:61g\`!:68*+71g81gp| 7 >61g2/61p71g1+71pv
>v>v>v>v < > ^
>#A 1 $^ ^ <
B 6^ <
^>^>^>^1 C |!`5p18:+1g18$ <
^ 9 p#p17*93p189p150 < >61g71g81gg+71g81gpv D
>071g81gp v ^ <
AND >+2\`!#^_> v
XOR +2% #^_> v
OR +1\`!#^_> v
NOT ! #^_> v
LEOSHFT 0 #^_>48*71g3+81gp v
REOSHFT $ 48*71g3+81gp #^_>v E
END v #^_> >61g2*61pv
@ F
v_^# `2:<
>71g81gg.48*71g2+81gp79*1-71g2+81g1+pv
^ <_v#!`2p15:+1g15p18+1g18<
^ < G
 
</lang>
The labelled points (1 to G) are:
1. Read in A and B,
2. Set the current operating row (R) to 4,
3. Set the current bit value (M) to 64,
4. Set Current operating column (C) to 3,
5. Check if M > A (i.e. bit is 0 or 1),
6. Write the bit value into location (R,C),
7. A = A - M,
8. M = M/2,
9. C++,
A&B. Storage of corresponding bits,
C. Initialise R & C to operation storage (OP) and M to 1,
D. Increment OP by M if true,
E. M = M*2,
F (2 rows below). Print value of OP, increment operation to perform by moving ">" down,
G. If doing the NOT, LEOSHFT or REOSHFT (current operation to perform > 3) only read A.
 
The code requires input be separated by spaces and only works for numbers less than 128, due to form of bit storage and ASCII locations not able to store beyond 127.
'''Inputs''':
<pre>
21 3
</pre>
 
{{out}}
<pre>
1 22 23 106 42 10
</pre>
 
=={{header|C}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.