MATLAB Function Reference    
bitshift

Bit-wise shift

Syntax

C = bitshift(A,k)

Description

C = bitshift(A,k,n) returns the value of A shifted by k bits. If k>0, this is same as a multiplication by 2k (left shift). If k<0, this is the same as a division by 2k (right shift). An equivalent computation for this function is
C = fix(A*2^k).

If the shift causes C to overflow n bits, the overflowing bits are dropped. A must contain nonnegative integers between 0 and BITMAX, which you can ensure by using the ceil, fix, floor, and round functions.

C = bitshift(A,k) uses the default value of n = 53.

Examples

Shifting 1100 (12, decimal) to the left two bits yields 110000 (48, decimal).

See Also

bitand, bitcmp, bitget, bitmax, bitor, bitset, bitxor, fix


  bitset bitxor