| MATLAB Function Reference | Search  Help Desk |
| bitshift | Examples See Also |
C = bitshift(A,k,n)C = bitshift(A,k)
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 isC = 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.
Shifting 1100 (12, decimal) to the left two bits yields 110000 (48, decimal).
C = bitshift(12,2)
C =
48
bitand Bit-wise AND
bitcmp Complement bits
bitget Get bit
bitmax Maximum floating-point integer
bitor Bit-wise OR
bitset Set bit
bitxor Bit-wise XOR
fix Round towards zero