Bit shifts double value in MATLAB R2010b

I am trying to perform a double-bit change operation in MATLAB 2010b. It seems that in newer versions of MATLAB this can be done using bitsra () , for example:

y = double(128);
bitsra(y,3)

but this feature is not available in older versions. What is the best way to achieve this?

+3
source share
1 answer

You can use a feature bitshiftavailable at least from MATLAB 2009a. From the documentation

c = bitshift(a, k)returns the value ashifted by a bit k.

  • When kpositive, 0-digit bits are shifted to the right.

  • k , a , 0- .

  • k , a , 1- .

MATLAB 2012b

>> bitsra(128, 3)

ans =

    16

MATLAB 2009a:

>> bitshift(128, -3)

ans =

    16

: bitshift , , bitshift(128.5, -3), , . , bitshift(128.5, -3), , , 128.5 . bitshift fi . -

>> bitshift(fi(128.5), -3)

ans =

    16.025
+6

All Articles