typecast
Convert data type without changing underlying data
Description
Examples
Input Arguments
Tips
typecast
is different from the MATLABcast
function in that it does not alter the input data.typecast
always returns the same number of bytes in the outputY
as in the inputX
. For example, casting the 16-bit integer 1000 touint8
withtypecast
returns the full 16 bits in two 8-bit segments (3 and 232), thus keeping the original value (3*256 + 232 = 1000). Thecast
function, on the other hand, truncates the input value to 255.The format of
typecast
output can differ depending on the system you use. Some computer systems store data starting with the least significant byte (an ordering called little-endian), while others start with the most significant byte (called big-endian). You can use theswapbytes
function to reverse the byte ordering from little-endian to big-endian (and vice versa).