Bitwise operations: Difference between revisions

Content added Content deleted
m (→‎{{header|AutoHotkey}}: Minor indentation and casing edit)
No edit summary
Line 538: Line 538:
\ a \ 7 bitwise # hex literals
\ a \ 7 bitwise # hex literals
</pre>
</pre>

=={{header|Mathematica}}==
Most functions are built-in or can be made really easily:
<lang Mathematica>
(*and xor and or*)
BitAnd[integer1, integer2]
BitXor[integer1, integer2]
BitOr[integer1, integer2]

(*logical not*)
BitNot[integer1]

(*left and right shift*)
BitShiftLeft[integer1]
BitShiftRight[integer1]

(*rotate digits left and right*)
FromDigits[RotateLeft[IntegerDigits[integer1, 2]], 2]
FromDigits[RotateRight[IntegerDigits[integer1, 2]], 2]

(*right arithmetic shift*)
FromDigits[Prepend[Most[#], #[[1]]], 2] &[IntegerDigits[integer1, 2]]
</lang>
The function BitShiftLeft, BitShiftRight, RotateRight, RotateLeft all take a second argument, which is the displacement, by default it is set to 1. BitAnd, BitXor and BitOr can handle more than 2 arguments:
<lang Mathematica>
BitXor[3333, 5555, 7777, 9999]
</lang>
gives back:
<lang Mathematica>
8664
</lang>


=={{header|MAXScript}}==
=={{header|MAXScript}}==