Convert fixed-point data types without changing underlying data
c = reinterpretcast(a, T)
c = reinterpretcast(a, T) converts the
a to the data type specified by
changing the underlying data. The result is returned in
a must be a built-in integer or
fi object with a fixed-point data type.
numerictype object with a fully specified
fixed-point data type. The word length of inputs
be the same.
reinterpretcast function differs from
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.
In the following example,
a is a signed
with a word length of 8 bits and a fraction length of 7 bits. The
a into an unsigned
a word length of 8 bits and a fraction length of 0 bits. The real-world
c are different,
but their binary representations are the same.
a = fi([-1 pi/4],1,8,7) T = numerictype(0,8,0); c = reinterpretcast(a,T)
a = -1 0.7890625 numerictype(1,8,7) c = 128 101 numerictype(0,8,0)
To verify that the underlying data has not changed, compare
the binary representations of
binary_a = bin(a) binary_c = bin(c)
binary_a = '10000000 01100101' binary_c = '10000000 01100101'