The workaround is to carry out the conversion manually, in Simulink or in MATLAB. As an example the MATLAB code to convert a 16-bit integer is outlined below and the Simulink alternative can be found in the attached model 'convert.mdl'.
isNegative = int16(bitget(u,16));
convertedValue = int16(bitset(u,16,0)) + (-2^15)*isNegative;
The code checks the most significant bit of the unsigned integer to determine if the value will become a positive or negative signed integer.
-If positive the converted value is just a simple conversion to a signed integer as no overflow will take place.
- If negative the the first 15 bits are converted to a signed integer and the smallest signed integer value (-2^15) is added to achieve the wrapped signed value of the original unsigned integer.
Best Answer