Integers
In this section...
“Integer Classes” on page 4-2
“Creating Integer Data” on page 4-3
“Arithmetic Operations on Integer Classes” on page 4-4
“Largest and Smallest Values for Integer Classes” on page 4-5
Integer Classes
MATLAB has four signed and four unsigned integer classes. Signed types enable you to
work with negative integers as well as positive, but cannot represent as wide a range of
numbers as the unsigned types because one bit is used to designate a positive or negative
sign for the number. Unsigned types give you a wider range of numbers, but these
numbers can only be zero or positive.
MATLAB supports 1-, 2-, 4-, and 8-byte storage for integer data. You can save memory and
execution time for your programs if you use the smallest integer type that accommodates
your data. For example, you do not need a 32-bit integer to store the value 100.
Here are the eight integer classes, the range of values you can store with each type, and
the MATLAB conversion function required to create that type:
Class Range of Values Conversion Function
Signed 8-bit integer -2^7 to 2^7 -1 int8
Signed 16-bit integer -2^15 to 2^15 -1 int16
Signed 32-bit integer -2^31 to 2^31 -1 int32
Signed 64-bit integer -2^63 to 2^63 -1 int64
Unsigned 8-bit integer 0 to 2^8 -1 uint8
Unsigned 16-bit integer 0 to 2^16 -1 uint16
Unsigned 32-bit integer 0 to 2^32 -1 uint32
Unsigned 64-bit integer 0 to 2^64 -1 uint64
4 Numeric Classes