MATLAB: How to perform a logical shift on a fi object in Fixed-Point Toolbox 1.3 (R14SP3)

bitshiftlogical?rightshift

When given a negative number of bits to shift, the Fixed-Point Toolbox BITSHIFT function performs an arithmetic shift to the right. I would like to know how I can perform a logical shift to the right instead.

Best Answer

This enhancement has been incorporated in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:
To perform a logical shift of 'k' bits to the right on a fi object 'a', you can use the following code:
k=2;
a=fi(-6.625,1,8,3);
c = bitshift(a, -k);
for i = 0:k-1
c=bitset(c,c.WordLength-i,0);
end
%