Matlab defaults to double-precision data. If you want to use 16 signed integer, you need to use the following command to convert it.
b = int 16(a);
Other types of functions are similar, such as
int,
int 16,
int32,
int64,
uint8,
uint 16,
uint32,
uint64
When the parameter is greater than 16 signed integer, it will be truncated automatically.
& gt& gtint 16( 100000)
ans =
32767
& gt& gtint 16(- 100000)
ans =
-32768
If there is a decimal part, round it off.
& gt& gtint 16(5.5)
ans =
six
2 operation
The operation between integer data and other types of data will be calculated with double data first, and then back to integer data.
& gt& gtint 16(5)*0.3
ans =
2
3 integer data check
You can use the isa command to check the data type.
& gt& gta=int 16(323)
a =
323
& gt& gtisa(a,' int 16 ')
ans =
1
4 Representation range of integer data
& gt& gtintmax('int 16 ')
ans =
32767
& gt& gtintmin('int 16 ')
ans =
-32768
Note that the return value is also the corresponding integer data.
5-time double data
In order to improve the accuracy, it is best to perform various operations under double precision.
c = double(b); Declaration or transformation of integer data.
Matlab defaults to double-precision data. If you want to use 16 signed integer, you need to use the following command to convert it.
b = int 16(a);
Other types of functions are similar, such as
int,
int 16,
int32,
int64,
uint8,
uint 16,
uint32,
uint64
When the parameter is greater than 16 signed integer, it will be truncated automatically.
& gt& gtint 16( 100000)
ans =
32767
& gt& gtint 16(- 100000)
ans =
-32768
If there is a decimal part, round it off.
& gt& gtint 16(5.5)
ans =
six
2 operation
The operation between integer data and other types of data will be calculated with double data first, and then back to integer data.
& gt& gtint 16(5)*0.3
ans =
2
3 integer data check
You can use the isa command to check the data type.
& gt& gta=int 16(323)
a =
323
& gt& gtisa(a,' int 16 ')
ans =
1
4 Representation range of integer data
& gt& gtintmax('int 16 ')
ans =
32767
& gt& gtintmin('int 16 ')
ans =
-32768
Note that the return value is also the corresponding integer data.
5-time double data
In order to improve the accuracy, it is best to perform various operations under double precision.
c = double(b);