# Operators in MATLAB - Bitwise Operators

Different types of operators are used in MATLAB. We will be discussing the Bitwise operators here. It is assumed that the reader of this article has some basic knowledge of MATLAB. For a detailed discussion of arithmetic operators click on the following link.

## Bitwise Operators

** bitand, bitor, bitxor, bitcmp,** and

*.*

**bitshift***Important Note: In all of the following examples the matrices A and B are supposed to be unsigned integers declared using data type uint8 unless otherwise specified.*

**bitand(A, B)**

This command returns the bitwise-and of the two arguments A and B. For example if A=[1 0; 1 1] and B=[0 1; 1 1] then bitand(uint8(A), uint8(B)) will result in [0 0;1 1]

**bitor(A, B)**

This command returns the bitwise-or of the two arguments A and B. For example if A=[1 0; 1 1] and B=[0 1; 1 1] then bitor(uint8(A), uint8(B)) will result in [1 1;1 1]

**bitxor(A, B)**

This command returns the bitwise-exclusive or of the two arguments A and B. For example if A=[1 0; 1 1] and B=[0 1; 1 1] then bitxor(uint8(A), uint8(B)) will result in [1 1;0 0]

**bitcmp(A)**

This command returns the bitwise-complement of the argument A. For example if A=[1 0; 1 1] then bitcmp(uint8(A)) will result in [254 255;254 254]

*Following is taken from MATLAB help.*

**bitshift(A, K)**

C = BITSHIFT(A,K) returns the value of A shifted by K bits. A must be an unsigned integer. Shifting by K is the same as multiplication by 2^K. Negative values of K are allowed and this corresponds to shifting to the right, or dividing by 2^ABS(K) and truncating to an integer. If the shift causes C to overflow the number of bits in theunsigned integer class of A, then the overflowing bits are dropped.

## Related Links

- Some Useful MATLAB Commands
- Operators in MATLAB - Arithmetic Operators

Arithmetic operators of MATLAB are discussed in this article. Information regarding Logical, Relational, Bitwise, Set and Special operators can also be found by following the links provided.

## More by this Author

- 4
This article presents a comparison between the time-frequency analysis and the Wavelet analysis. The Short-time Fourier transform is used for the purpose of time-frequency analysis. We have presented examples to...

- 5
Samples of Argument tasks given in GRE and other similar tests like TWe, GMAT etc.

- 7
Learn how to write an effective curriculum vitae, or resume, and look at several examples.

No comments yet.