Convert fixed-point or integer data types without changing underlying data
reinterpretcast function differs from the MATLAB®
cast functions in that it only operates on
fi objects and
built-in integers, and it does not allow the word length of the input to change.
fi Object to New Data Type
In this example,
a is a signed
fi object with a word length of 8 its and a fraction length of 7 bits. The
reinterpretcast function converts
a into an unsigned
c with a word length of 8 bits and a fraction length of 0 bits. The real-world values of
c are different, but their binary representations are the same.
a = fi([-1 pi/4],1,8,7)
a = -1.0000 0.7891 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 8 FractionLength: 7
T = numerictype(0,8,0); c = reinterpretcast(a,T)
c = 128 101 DataTypeMode: Fixed-point: binary point scaling Signedness: Unsigned WordLength: 8 FractionLength: 0
To verify that the underlying data has not changed, compare the binary representations of
binary_a = bin(a)
binary_a = '10000000 01100101'
binary_c = bin(c)
binary_c = '10000000 01100101'
a — Input fixed-point or integer array
scalar | vector | matrix | multidimensional array
Input fixed-point or integer array, specified as a scalar, vector, matrix, or multidimensional array.
The word length of inputs
T must be
Complex Number Support: Yes