Bitwise operations: Difference between revisions

Added a solution for MATLAB
m (→‎{{header|LSE64}}: {{incorrect|LSE64|No reason given.}})
(Added a solution for MATLAB)
Line 733:
gives back:
<lang Mathematica>8664</lang>
 
=={{header|MATLAB}}==
Newer versions of MATLAB have even more bitwise operations than those demonstrated here. A complete list of bitwise operations for the newest version of MATLAB can be found at [http://www.mathworks.com/help/toolbox/fixedpoint/ref/f20333.html#bp7caxc-42 MathWorks]
 
<lang MATLAB>function bitwiseOps(a,b)
 
disp(sprintf('%d and %d = %d', [a b bitand(a,b)]));
disp(sprintf('%d or %d = %d', [a b bitor(a,b)]));
disp(sprintf('%d xor %d = %d', [a b bitxor(a,b)]));
disp(sprintf('%d << %d = %d', [a b bitshift(a,b)]));
disp(sprintf('%d >> %d = %d', [a b bitshift(a,-b)]));
 
end</lang>
 
Output:
<lang MATLAB>>> bitwiseOps(255,2)
255 and 2 = 2
255 or 2 = 255
255 xor 2 = 253
255 << 2 = 1020
255 >> 2 = 63</lang>
 
=={{header|MAXScript}}==
Anonymous user