Thursday, 2 June 2016

MATLAB Programming 24 - Functions for bitwise operations (2)

Create a script file and type the following code:

a = 60;      % 60 = 0011 1100

b = 13;      % 13 = 0000 1101

c = bitand(a, b)      % 12 = 0000 1100

c = bitor(a, b)      % 61 = 0011 1101

c = bitxor(a, b)      % 49 = 0011 0001

c = bitshift(a, 2)      % 240 = 1111 0000 */

c = bitshift(a,-2)      % 15 = 0000 1111 */

When you run the file, it displays the following result:

c = 12

c = 61

c = 49

c = 240

c = 15


No comments:

Post a Comment