Mathematics Previous page   Next Page

Integer Data Types

Integer data types in MATLAB take on integer values in a specified range. For example, an integer of type int8 can take any of the 28 possible values of signed 8-bit integers in the range -128 to 127. Integer data types are useful for storing data that can be described using only integers, such as image files. The following table lists the integer data types that support arithmetic operations and their ranges.

Data Type
Description
Range of Values
int8
Signed 8-bit integer
-128 to 127
uint8
Unsigned 8-bit integer
0 to 255
int16
Signed 16-bit integer
-215 to 215 - 1
uint16
Unsigned 16-bit integer
0 to 216 - 1
int32
Signed 32-bit integer
-231 to 231 - 1
uint32
Unsigned 32-bit integer
0 to 232 - 1

To assign an integer data type to a number or variable, use one of the functions listed in the first column of the table. For example,

sets the value of x to be 5 with data type int8. You can verify the data type of the result using the class command.

When you convert a number to one of the integer data types, MATLAB rounds the result to the nearest integer. For example,

For numbers that are halfway between two integers, MATLAB rounds up if the number is positive and rounds down if the number is negative. For example,


Previous page  Integer Mathematics Largest and Smallest Values for Integer Data Types Next page

© 1994-2005 The MathWorks, Inc.