MATLAB: Do I receive unexpected results when I use BITSHIFT operation on fi objects in Fixed-Point Toolbox

bitbitshiftleftleft-shiftrightright shiftshiftshiftingwrong

I am trying to use the BITSHIFT operation as follows:
a = fi(3, true, 4, 0);
b = bitshift(a, -1);
At the end of the BITSHIFT operation I expect the variable b to hold a value of 1. However, it holds a value of 2.

Best Answer

This enhancement has been incorporated in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:
The BITSHIFT operation obeys the OverflowMode and RoundMode properties of fimath objects. By default, the RoundMode property is set to "nearest". Therefore:
3 (decimal) = 0011 (binary)
when right shifted one bit yields
1.5 (decimal) = 0001.1 (binary) before rounding
When rounded to "nearest", this rounds to
2 (decimal) = 0010 (binary)
The logicalshift.m file attached with this solution mimics the behavior of the C language bitshift operators (">>" and "<<").